Computer Science · CSTA 2-AP-10, 2-AP-13 · 信息科技 · Algorithms

Algorithms: sorting & searching

A search engine finds answers among billions of pages in under a second. That takes more than a fast computer — it takes a smart algorithm: a step-by-step method for solving a problem. How big is the gap between a smart and a slow algorithm? Finding one name among a million: the slow way can take a million looks; the smart way never needs more than 20.

Your mission: start as a Shuffler. Race three sorting algorithms, crack a secret number with binary search, design the rules for a maze robot — then BE the algorithm: put mystery boxes in order from light to heavy using a balance scale and as few weighings as possible. Top rank: Big-O Master.

The great sorting race

Three algorithms sort the same bars. Every comparison or move counts as one step. Who needs the fewest? Switch to nearly-sorted or reversed data — does the winner change? Click a lane to see how that algorithm works.

🚀 Extra lanes:
Advanced: comparisons, formulas and Big-O

📏 Experiment: how do comparisons grow with n?

The computer runs each algorithm on the current kind of data at n = 8, 16, 32, 64 and 128 (random data: average of 3 runs) and counts the comparisons. Dashed lines are the formulas n(n−1)/2 and n·log₂n.

🎯 Challenge

Design an algorithm for a maze robot

The robot can’t see the whole maze — it only feels the walls next to it. Each step it checks your rules from top to bottom and does the first one it can. Reorder them with ▲▼ and switch rules off with ⏻. Which order always escapes? Then compare with the shortest path found by breadth-first search.

🧩 Rule blocks (checked top to bottom)

0robot steps
—shortest path
Hint: the right-hand rule

Keep your right hand on the wall: turn right if you can, else go straight, else turn left, else turn around. In a maze without loops this always reaches the exit — but rarely by the shortest route.

Main mission: be the sorting algorithm

Each box holds a different weight, but you can’t see it. Click two boxes to put them on the scale (1 comparison); press Swap to switch their places. Put the boxes in order from light (left) to heavy (right), then check. Fewer comparisons = more stars.

0/12total stars
1/4level
0comparisons
—rank

WEIGHING LOG (“<” means lighter):
⚠️ Don’t mix up:Binary search only works on a list that is already sorted! An unsorted list has to be checked one by one (linear search). That’s why computers often sort first — every search after that is much faster.

Go further

Test yourself

🧠 Quiz

Pick the best answer and read the explanation.

🗂️ Sort it: sorting, searching or path-finding?

Drag each item (or tap it, then tap a box) into the right group.

👩‍🏫 Teacher notes

US standards: CSTA K-12 CS Standards (2017) 2-AP-10 (use flowcharts and/or pseudocode to address complex problems as algorithms), 2-AP-13 (decompose problems into parts); also 2-AP-17 (test with a range of cases — new data, new mazes). Georgia K-12 Computer Science Standards (grades 6–8): CSS.KC.6-8.18 (a problem can have multiple solutions), 19 (solve problems iteratively), 20.5 (implement a simple algorithm); CSS.CT.6-8.32.1 (decomposition, pattern recognition, algorithmic thinking, abstraction), 35.2 (Boolean operators to improve searches), 36.1–36.3 (algorithmic problem-solving of rising complexity). Codes as listed in GaDOE’s 6–8 CS framework (via CodeHS); check wording against the GaDOE document.

China’s curriculum: Compulsory Education Information Technology Curriculum Standard (2022), core strand “algorithms” (算法). Stage 3, grade 5 module “Algorithms around us” (身边的算法: describe algorithms in words and flowcharts, feel the difference in efficiency, e.g. searching and sorting); Stage 4 (grades 7–9) applies algorithms in programming projects. Textbook editions and lesson numbers vary.

Notes: in the race, “steps” = comparisons + moves (swaps or writes); bubble sort stops early when a pass makes no swaps; merge sort is the bottom-up version. The chart shows worst-case counts from formulas, not measured times; “1 billion steps per second” is only an assumption for comparison. The minimum worst-case comparisons for sorting 4, 5, 6 and 8 items (5, 7, 10, 16) are known results, written from the author’s knowledge.

Suggested use: start unplugged — students act out bubble and selection sort with playing cards and count steps. Use the guessing game to discuss why doubling the list adds only one guess. In the maze, have students find a rule order that always works and discuss “always works” vs “fastest”. After the main mission, ask students to explain their strategy and compare it with merge sort.