อัลกอริทึม
แนะนำใหม่
12:39
GAC024 คณิตศาสตร์แบบไม่ต่อเนื่อง
สมาชิกซ้ำในเซตถูกนับเพียงครั้งเดียว การถ่วงบิ้นอาจเกินความกว้างที่กำหนด และเส้นทางที่ใช้ขอบน้อยที่สุดอาจไม่ใช่เส้นที่มีน้ำหนักน้อยที่สุดที่สุด discrete…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| algorithm/ˈælɡərɪθəm/ | อัลกอริทึม |
| flowchart/ˈfləʊtʃɑːt/ | แผนภาพการไหล |
| pseudocode/ˈsuːdəʊkəʊd/ | โค้ดลวง |
| tracing/ˈtreɪsɪŋ/ | การติดตาม |
| binary search/ˈbaɪnəri sɜːtʃ/ | การค้นหาแบบแบ่งครึ่ง |
| linear search/ˈlɪnɪə sɜːtʃ/ | การค้นหาแบบเชิงเส้น |
| efficiency/ɪˈfɪʃənsi/ | ประสิทธิภาพ |
Say which inputs the procedure must handle
- An algorithm 算法 describes unambiguous steps for a task. A procedure solving a stated finite task must terminate and give the correct result for every allowed input.
- A successful trace on one input shows that case, not a proof for all inputs. Boundary and empty-input cases can expose errors that a typical example misses.
สิ่งใดจำเป็นต่อการเป็นอัลกอริทึม? เลือกทุกข้อที่ใช้ได้
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ขั้นตอนการแก้ปัญหาโจทย์ finite ที่กำหนด ต้องมีขั้นตอนที่ชัดเจน ผลลัพธ์ถูกต้อง และการสิ้นสุดกับอินพุตที่อนุญาต Pseudocode และ flowchart เป็นการนำเสนอ ไม่ใช่ข้อกำหนดต้องใช้ภาษาโปรแกรม某一 particular
Represent choices and updates clearly
- A flowchart 流程图 uses a decision diamond, process rectangle, input/output parallelogram and start/stop terminal, connected by directed flow arrows.
- Pseudocode 伪代码 describes the steps without requiring one implementation language. State assignment meaning, index origin, loop bounds and branch conditions before tracing.
![Binary search for 7 in [1, 3, 5, 7, 9, 11]: first the middle index 2 holds 5 < 7, so go right; second, the middle index 4 holds 9 > 7, so go left; third, index 3 holds 7, found after three comparisons under this convention](/learn-media/gac_mathematics/assets/0404-binary-search-steps.png?v=1794647931)
จับคู่รูปร่าง flowchart แต่ละรูปกับความหมายของมัน
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ใช้ process rectangles, decision diamonds และ start/stop terminals ตามที่กำหนด Input/output ปกติแสดงด้วย parallelogram ให้ฉลาก decision branches และทิศทาง flow
Record the actual variable values
- Tracing 追踪 follows the stated updates in order. A temporary variable may preserve a value that would otherwise be overwritten.
- Show low, high, middle and compared value for a binary search; show every changed variable for an arithmetic loop. Judge what the procedure does, not only its intended purpose.
A specified binary-search convention. Use zero-based inclusive bounds and floor of their average for the middle. Searching for 7 in [1,3,5,7,9,11] compares index 2/value 5, index 4/value 9, then index 3/value 7. The comparison count is three under this convention.
Linear เปรียบเทียบกับ binary search
การแบ่งครึ่งชนะการเช็คทีละตัว และช่องว่างยิ่งกว้างขึ้นเมื่อรายการยาวขึ้น
การใช้ขอบเขตinclusive แบบ zero-based และ floor((low+high)/2) Binary search ใช้การเปรียบเทียบกี่ครั้งเพื่อหาค่า 7 ใน [1,3,5,7,9,11]?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ดัชนีกลางคือ 2, 4 แล้วตามด้วย 3 ซึ่งมีค่า 5, 9 และ 7下进行การเปรียบเทียบสามครั้งตามนัยนิยามที่กำหนด
Compare work under its assumptions
- A linear search 线性查找 can stop early but may inspect all n items. A binary search repeatedly halves a sorted search range and needs consistent bound updates.
- Efficiency 效率 describes how required work scales with input size under a defined model. Sorting first has its own cost; an unsorted input cannot rely on binary search's ordering guarantee.
สำหรับรายการที่มี getItem One Million ที่เรียงลำดับแล้วโดยประมาณ Binary search ต้องการการเปรียบเทียบค่ากลางกี่ครั้งในกรณีแย่ที่สุด?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
การเปรียบเทียบแต่ละครั้งลดช่วงการค้นหาที่เหลือลงครึ่งหนึ่ง ประมาณ 20 ครั้งเพียงพอสำหรับรายการที่มี ordered items的数量 One Million สิ่งนี้ไม่รวมต้นทุนการ sort ก่อนหน้า
Binary search ทำงานบนรายการที่ไม่เรียงลำดับ ได้ช้าลงเท่านั้น
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
หากขาดการจัดลำดับที่ต้องการ การทิ้งครึ่งหนึ่งอาจพลาด item ที่มีอยู่บางกรณีอาจสำเร็จโดยบังเอิญแต่ความถูกต้องไม่ได้รับประกัน
Check zero and the last allowed index. Sheet 4.4 examines a sum loop using i less than n, which misses the last term. Its Euclidean trace also explains termination: each positive divisor is replaced by a smaller nonnegative remainder until zero is reached.