computer-science/what-is-an-algorithm-watch-two-recipes-race-to-sort-six-bars.md
What Is an Algorithm? Watch Two Recipes Race to Sort Six Bars
An algorithm is a recipe so precise that someone who doesn't understand the goal could still follow it and get the right answer. Computers are exactly that someone.
This page teaches the idea with sorting: step through bubble sort and selection sort on the same row of bars, count every comparison and swap, play the computer yourself, and see why the way the work grows decides whether a sort takes milliseconds or hours. Includes a short, runnable JavaScript version of both.
$ ls computer-science/
see all →
computer-science/heaps-how-a-computer-always-knows-the-most-urgent-item-without-sorting.md
Heaps: how a computer always knows the most urgent item without sorting everything
A hospital waiting room, a game's task list and a map app all need the same thing: the most urgent item, right now, while new items keep…
computer-science/coin-change-why-grabbing-the-biggest-coin-first-can-fail-and-how-a-tab.md
Coin change: why grabbing the biggest coin first can fail, and how a table fixes it
A cashier owes 6 cents and has coins worth 1, 3 and 4. Grabbing the biggest coin first uses three coins, but two 3s do it in two. This…
computer-science/binary-search-trees-why-the-order-you-insert-numbers-changes-how-fast.md
Binary search trees: why the order you insert numbers changes how fast you can find them
A binary search tree keeps numbers in order with one rule: smaller goes left, bigger goes right. Build one yourself, watch a search light…
computer-science/merge-sort-how-splitting-a-list-in-half-again-and-again-sorts-it-with.md
Merge sort: how splitting a list in half again and again sorts it with far less work
How do you sort 10,000 numbers without making millions of comparisons? Merge sort never sorts a big pile. It splits the list until every…
computer-science/hash-tables-how-a-computer-finds-one-name-among-thousands-without-chec.md
Hash tables: how a computer finds one name among thousands without checking them all
Your phone finds one contact among thousands without reading them all. The trick is a hash table: a row of numbered slots and a small…
computer-science/stacks-and-queues-why-undo-takes-the-newest-item-and-a-printer-takes-t.md
Stacks and queues: why undo takes the newest item and a printer takes the oldest
Press undo and the last thing you typed disappears first. Send documents to a shared printer and the first one is printed first. Both are…