TwiddleLab / Courses / Code
Algorithms in Motion
Race searches and sorts side by side and see why some algorithms grow so much faster.
Best after: Build with Python, Growth: Exponents and Logs
Lessons
- Counting Steps (5 min): The step count is how many basic steps a program takes. It grows with the size of the data, n.
- Linear vs Binary Search, Revisited (7 min): Linear search checks items one by one: up to n checks.
- Selection Sort (7 min): Selection sort: find the smallest of the unsorted part, swap it to the front, repeat.
- Insertion Sort (7 min): Insertion sort: take the next card and slide it left past every bigger card.
- Big O: How the Bars Grow (7 min): Big O names how the step count grows with n: O(1), O(log n), O(n), O(n²).
- Merging Sorted Piles (7 min): To merge two sorted piles, compare only the two top cards; the smaller goes out.
- Merge Sort: Merge, Then Merge Again (7 min): Merge sort: one card is already sorted. Merge pairs, then fours, then eights, until one pile is left.
- Quicksort: Pick a Pivot (7 min): Quicksort: pick a pivot, send smaller items left and bigger right, then do the same on each side.
- Sorting Networks (7 min): A comparator takes two numbers and sends the smaller up, the bigger down.
- Greedy Choices (7 min): A greedy algorithm takes the best-looking choice at each step and never looks back.
- Algorithm Race (7 min): A benchmark races programs on the same data, at the same size, with the same counter.
Lessons are interactive and need JavaScript. Turn it on to play them.