Standard algorithms
แนะนำใหม่
9:16
รอบชีวิตการพัฒนาโปรแกรม
ทุกแอปในโทรศัพท์ของคุณเขียนโดยบุคคลเช่นนี้ แต่เขาไม่ได้เริ่มด้วยการพิมพ์โค้ด ก่อนบรรทัดแรก ปัญหาถูกศึกษา, ทางออก…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| algorithms/ˈælɡərɪθəmz/ | A finite sequence of precise steps for solving a problem or carrying out a task. |
| linear search/ˈlɪnɪə sɜːtʃ/ | การค้นหาแบบเชิงเส้น |
| bubble sort/ˈbʌbl sɔːt/ | การเรียงลำดับแบบฟองอากาศ |
| counting/ˈkaʊntɪŋ/ | การนับจำนวน |
| totalling/ˈtəʊtəlɪŋ/ | การรวมผล |
| value/ˈvæljuː/ | An amount, number or item assigned to a variable or expression, or held by a data object. |
| list/lɪst/ | |
| sorting/ˈsɔːtɪŋ/ | |
| max/min | |
| average/ˈævrɪdʒ/ | |
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| pass/pæs/ | |
| ascending order |
สูตรมาตรฐานคลาสสิก
- อัลกอริทึมมาตรฐานบางตัวปรากฏซ้ำๆ
- คุณต้องรู้จัก การค้นหาแบบเชิงเส้น, การเรียงลำดับแบบฟองสบู่ (bubble sort) และรูปแบบการนับ/ผลรวม
- แต่ละตัวสั้นแต่คุ้มค่าที่จะจดจำทันที
การค้นหาเชิงเส้น
DECLARE Found : BOOLEAN
Found ← FALSE
FOR I ← 1 TO 10
IF List[I] = SearchValue
THEN
Found ← TRUE
ENDIF
NEXT I
OUTPUT Found
- การค้นหาแบบเชิงเส้น ตรวจสอบแต่ละรายการตามลำดับตั้งแต่ต้น จนกว่าจะพบค่าที่ต้องการ (หรือถึงท้ายรายการ)
- ใช้ได้กับรายการทุกชนิด — ไม่ต้องเรียงลำดับก่อน

แผนภาพการไหลสำหรับอัลกอริทึมผลรวม โดยใช้สัญลักษณ์มาตรฐาน (เริ่มต้น/สิ้นสุด, เข้า/ออก, กระบวนการ, การตัดสินใจ)

Standard algorithms
compare adjacent, swap if needed
Step through a bubble sort — compare neighbours and swap until everything is in order.
A linear search finds a value by:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Linear search examines items one by one until it finds the value or reaches the end.
การ์ดนี้ได้รับการแก้ไขแล้ว จึงแสดงเป็นภาษาอังกฤษจนกว่าคำแปลจะได้รับการอัปเดต
Bubble sort
FOR Pass ← 1 TO 9
FOR I ← 0 TO 8
IF List[I] > List[I + 1]
THEN
Temp ← List[I]
List[I] ← List[I + 1]
List[I + 1] ← Temp
ENDIF
NEXT I
NEXT Pass
- A bubble sort 冒泡排序 compares each side-by-side pair and swaps them if they are out of order.
- It repeats this until no more swaps are needed — leaving the list sorted.

A bubble sort puts a list in order by:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
It swaps out-of-order neighbours and repeats passes until no swaps are needed.
ผลรวม, การนับ, สูงสุด/ต่ำสุด/เฉลี่ย
- การรวมผล (Totalling) — รวบรวมผลสะสม:
Total ← Total + Value - การนับ (Counting) — เพิ่ม 1 ทุกครั้งที่เกิดเหตุการณ์:
Count ← Count + 1 - สูงสุด/ต่ำสุด — เก็บค่าที่ใหญ่ที่สุด/เล็กที่สุดที่พบมาจนถึงตอนนี้
- เฉลี่ย — นำผลรวมหารด้วยจำนวนค่าทั้งหมด

Which line adds a value to a running total?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Total ← Total + Value accumulates a sum; Count ← Count + 1 counts occurrences.
Match each standard algorithm to how it works.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
These four — search, sort, total and max — are the building blocks of most exam algorithms.
Using totalling on the list [2, 4, 6, 8], what is the final total?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
2 + 4 + 6 + 8 = 20.
คุณเข้าใจแล้ว
- การค้นหาแบบเชิงเส้น ตรวจสอบแต่ละรายการตามลำดับ (ใช้ได้กับรายการทุกชนิด)
- การเรียงลำดับแบบฟองสบู่ สลับเพื่อนบ้านที่ผิดลำดับ ทำซ้ำจนเรียงลำดับ
- การรวมผล (
Total ← Total + Value) และ การนับ (Count ← Count + 1) - max/min = เก็บค่าที่ดีที่สุดไว้; average = ผลรวม ÷ จำนวน
A linear search looks for 7 in the list 4 9 2 7 5. How many items does it compare before it finds 7, including 7 itself?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
It checks 4, 9, 2, then 7: four comparisons.
A program has totalled 5 marks to get 340. What is the average?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Average = total ÷ count = 340 ÷ 5 = 68.
การ์ดนี้เป็นการ์ดใหม่ จึงแสดงเป็นภาษาอังกฤษจนกว่าคำแปลจะพร้อม
You've got it
- linear search checks each item in turn (works on any list)
- bubble sort swaps out-of-order neighbours, repeating until sorted
- totalling (
Total ← Total + Value) and counting (Count ← Count + 1) - max/min 最大值/最小值 = keep the best so far; average = total ÷ count
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้