Data Structures & Algorithms
The core toolkit, built from zero — start with what a variable even is, then climb through searching, sorting, hashing, trees, graphs, and dynamic programming. Every lesson is a live animation you can run, scrub, and feed your own input. The full dependency map lives on /map.
Foundations
- 1
What is a Variable?
EasyArray▶ animatedThe smallest idea in all of code: a labeled box that holds one value — and that value can change.
- 2
What is an Array?
EasyArray▶ animatedBefore any algorithm: an array is a row of numbered boxes. Meet the index and the value.
- 3
One Box at a Time
EasyArray▶ animatedWhy searching is even a problem: a computer can't see all the boxes at once — it opens them one by one.
- 4
Bits & Binary
EasyArray▶ animatedNumbers are secretly rows of on/off light switches — and flipping them lets you do clever tricks like erasing duplicates with XOR.
Searching
- 5
Linear Search
EasyArray▶ animatedCheck each element one by one until you find the target. The O(n) baseline.
- 6
What is Sorted?
EasyArray▶ animated'Sorted' isn't just 'tidy' — it's a promise: each box is never smaller than the one before it.
- 7
Binary Search
EasyArray▶ animatedFind a target in a sorted array by repeatedly halving the search space.
Arrays & strings
- 8
Two Pointers
EasyArray▶ animatedFind a pair summing to a target in a sorted array by converging two pointers.
- 9
Sliding Window
MediumArray▶ animatedGlide a contiguous window across an array or string, updating the answer as it moves — one pass instead of re-checking every range.
- 10
Prefix Sums
EasyArray▶ animatedPrecompute running totals once, then answer any range-sum in O(1) with a single subtraction.
Hashing
Stacks, queues & lists
- 13
Stack & Queue
EasyArray▶ animatedLIFO vs FIFO: a stack pops the newest, a queue dequeues the oldest.
- 14
Monotonic Stack: Next Greater Element
MediumArray▶ animatedKeep a stack that stays sorted in one direction to find each number's next-greater element in a single O(n) pass.
- 15
Linked List Traversal
EasyArray▶ animatedFollow next pointers from head to null — a pointer is a reference to a node.
- 16
KMP String Matching
HardArray▶ animatedFind a pattern inside a text without ever re-checking characters you already matched, using the LPS table.
- 17
Greedy: Activity Selection
MediumArray▶ animatedPick the most non-overlapping activities by sorting on END time and always grabbing the next one that fits.
Sorting
- 18
Bubble Sort
EasyArray▶ animatedSort by repeatedly swapping adjacent out-of-order pairs until settled.
- 19
Insertion Sort
EasyArray▶ animatedGrow a sorted prefix by inserting each next element into its correct spot.
- 20
Merge Sort
MediumArray▶ animatedDivide the array in half, sort each half, then merge them. O(n log n).
- 21
Quicksort
MediumArray▶ animatedPick a pivot, push smaller values left and bigger ones right, then repeat on each side. O(n log n) on average.
Recursion & dynamic programming
- 22
Recursion: Factorial
EasyRecursion▶ animatedSee recursion as a call stack: calls push on the way down, pop on the way up.
- 23
Backtracking
HardTree▶ animatedExplore choices as a decision tree — make a choice, recurse, then UNDO it and try the next one.
- 24
DP: Climbing Stairs
EasyGrid / DP▶ animatedCount ways to climb n stairs (1 or 2 at a time) by filling a DP table.
- 25
DP: Unique Paths (Grid)
EasyGrid / DP▶ animatedCount right/down paths across a grid — the clearest 2D DP, where the table IS the map.
- 26
DP: Coin Change
MediumGrid / DP▶ animatedFewest coins to make an amount by building up a best-answer table, one amount at a time.
- 27
DP: Longest Increasing Subsequence
MediumGrid / DP▶ animatedFind the longest run of increasing numbers (not necessarily next to each other) with a dp[] table.
- 28
DP: 0/1 Knapsack
MediumGrid / DP▶ animatedPack a weight-limited bag for maximum value by filling a 2D best-value table.
- 29
DP: Edit Distance
HardGrid / DP▶ animatedFewest insert/delete/replace edits to turn one word into another — the classic 2D string DP.
Trees
- 30
Tree Traversal (In-order)
MediumTree▶ animatedIn-order traversal of a BST (left → node → right) visits values in sorted order.
- 31
Trie (Prefix Tree)
MediumTree▶ animatedA tree of letters where words that start the same share the same path — the magic behind autocomplete.
- 32
Binary Search Tree
MediumTree▶ animatedKeep left < node < right at every node, and searching becomes one walk straight down — binary search on a tree.
- 33
B-Tree Insert (how an index grows)
MediumTree▶ animatedA BST can grow into a lopsided line. A B-tree stays short by SPLITTING: when a node overfills, its middle key jumps up. Watch it stay balanced.
- 34
Segment Tree: Range Sum
HardTree▶ animatedStore the sum of every range in a tree so a range-sum query reads a few nodes (O(log n)) instead of adding every element.
- 35
Heap (Priority Queue)
MediumTree▶ animatedA tree that always keeps the smallest (or largest) on top — and secretly lives in a plain array.
- 36
Heapsort
MediumTree▶ animatedBuild a max-heap, then keep pulling the biggest off the top and parking it at the end. Guaranteed O(n log n), in place.
- 37
Union-Find (Disjoint Sets)
MediumTree▶ animatedA tiny structure that answers 'are these two things connected?' almost instantly — the heart of network and MST algorithms.
Graphs
- 38
How Graphs Are Stored
EasyGraph▶ animatedA graph is dots and lines — but a computer stores it as numbers. See the picture, the matrix, and the list as the same graph.
- 39
Breadth-First Search
MediumGraph▶ animatedExplore a graph level by level using a queue — nearest nodes first.
- 40
Depth-First Search
MediumGraph▶ animatedExplore a graph by going deep down one path before backtracking.
- 41
Topological Sort
MediumGraph▶ animatedOrder tasks so every prerequisite comes before the task that needs it — using DFS on a directed graph.
- 42
Dijkstra's Shortest Path
HardGraph▶ animatedFind the cheapest route through a weighted graph by always finalizing the closest node next.
- 43
Bellman-Ford Shortest Path
HardGraph▶ animatedFind shortest paths even with NEGATIVE roads by relaxing every edge V-1 times.
- 44
All-Pairs Shortest Paths (Floyd-Warshall)
HardGrid / DP▶ animatedFind the cheapest cost between EVERY pair of towns by filling a distance matrix with a triple loop.
- 45
Minimum Spanning Tree (Kruskal)
MediumGraph▶ animatedConnect every town with the cheapest total road and no loops by adding edges cheapest-first.
- 46
Routing (shortest path)
MediumGraph▶ animatedHow the internet picks a route: the fastest path, not the fewest hops. Watch routers find the lowest-latency way across a mesh.