CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Courses / Code

Algorithms in Motion

Race searches and sorts side by side and see why some algorithms grow so much faster.

Intermediate · 11 lessons · Free, no account needed

Best after: Build with Python, Growth: Exponents and Logs

Start the course

Lessons

  1. Counting Steps (5 min): The step count is how many basic steps a program takes. It grows with the size of the data, n.
  2. Linear vs Binary Search, Revisited (7 min): Linear search checks items one by one: up to n checks.
  3. Selection Sort (7 min): Selection sort: find the smallest of the unsorted part, swap it to the front, repeat.
  4. Insertion Sort (7 min): Insertion sort: take the next card and slide it left past every bigger card.
  5. 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²).
  6. Merging Sorted Piles (7 min): To merge two sorted piles, compare only the two top cards; the smaller goes out.
  7. 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.
  8. Quicksort: Pick a Pivot (7 min): Quicksort: pick a pivot, send smaller items left and bigger right, then do the same on each side.
  9. Sorting Networks (7 min): A comparator takes two numbers and sends the smaller up, the bigger down.
  10. Greedy Choices (7 min): A greedy algorithm takes the best-looking choice at each step and never looks back.
  11. 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.

Loading TwiddleLab