Data structures from scratch
A course in short lessons: each one explains an idea with code you can change and run, then quizzes you. Whatever you miss comes back at the end until you get it. You don't need to know much programming; just be willing to try things. Your progress is saved in this browser, no account needed.
0/32 lessons0 xp0 day streak
Unit 1Before we start
- 1What is a data structure?Data, the way it's arranged and what you can do with it. Why this course uses JavaScript.Start →
- Values and referencesWhy changing a "copied" array also changes the original. The foundation of lists and trees.
- What it costs: Big OCounting steps instead of seconds: O(1), O(log n), O(n), O(n²). The language of everything that follows.
Unit 2Arrays
- Arrays and indexesSlots in a row, numbered from 0: why reading any of them costs the same, and grids as arrays of arrays.
- Walking, adding and removingWhy adding at the end is cheap and at the front is expensive, how to search without an index, and map, filter and reduce.
- Two pointers and sliding windowsTwo indexes walking at once turn many O(n²) problems into O(n). Half of all interview questions.
Unit 3Stacks and queues
- Stacks: last in, first outA stack of plates in code: push and pop, the undo button, the call stack and balanced parentheses.
- Queues: first come, first servedThe tortilla shop line in code, why shift is expensive and how to make an O(1) queue with an index.
- Circular queue and dequeA fixed-size queue that wraps around with modulo, and a queue that lets you in and out at both ends.
Unit 4Linked lists
- Nodes and pointersA list made of little boxes pointing to each other: walking it, adding at the front in O(1) and at the end with a tail.
- Removing, reversing and mergingChanging arrows instead of moving data: removing a node, reversing a list in place and merging two sorted lists.
- Doubly linked lists and cyclesNodes that also point backwards, sentinels at both ends, and the tortoise and the hare to detect a cycle.
Unit 5Hash tables
- The hash function and the bucketsTurning a key into a drawer number so you can find it without walking through anything. Collisions, load factor and why it's O(1).
- Map and Set: JavaScript's hash tablesThe hash tables the language already has: counting, grouping, removing duplicates and finding pairs in a single pass.
Unit 6Recursion
- A function that calls itselfBase case, the call stack and why naive Fibonacci blows up. The tool for trees and graphs.
- Divide and conquerSplitting the problem in half: binary search in O(log n) and merge sort in O(n log n).
Unit 7Trees
- Binary treesRoot, children, leaves, height and depth. Nodes that point to two nodes, and how to build them in JavaScript.
- Depth-first traversalsPreorder, inorder and postorder: the same tree in three orders. Height, mirroring and the common ancestor.
- Level-order traversalVisiting the tree floor by floor with a queue (BFS). Levels as arrays and the view from the right.
Unit 8Binary search trees
- Searching and inserting in a BSTSmaller to the left, bigger to the right: the rule that lets you search by discarding half the tree at each step.
- Deleting, and why balancing mattersThe three cases of deleting, the tree that turns into a list with sorted data, and how a rotation fixes it.
Unit 9Heaps
- A tree stored in an arrayThe min-heap: the smallest always on top, no pointers, and push or pop in O(log n).
- Priority queuesThe most urgent goes first, not the first to arrive. And the k largest out of a million without sorting the million.
Unit 10Graphs
- Dots and lines: what a graph isVertices and edges, with or without arrows, with or without weights. Storing them as an adjacency list or a matrix.
- Walking a graph: BFS and DFSBreadth-first with a queue, depth-first with a stack. Distances, components and the islands on a map.
- The shortest path: DijkstraWhen edges weigh differently, fewer hops isn't fewer kilometers. The algorithm behind maps.
- What comes first: topological orderCourses with prerequisites, tasks that depend on others: lining them up without breaking any dependency.
Unit 11Advanced structures
- Trie: the prefix treeA tree with one letter per edge: find words and autocomplete no matter how many are stored.
- Union-Find: are they in the same group?Disjoint sets with a single array of parents: merge groups and ask whether two things are together, almost in O(1).
- Range sums: prefixes and FenwickSum any stretch of an array in O(1) with prefix sums, and in O(log n) even when the data changes, with a Fenwick tree.
- LRU cacheA fixed-size memory that forgets what you haven't used for the longest: with a JavaScript Map, and with a map plus a doubly linked list.
- Dynamic programming: never compute twiceStore what you already computed in a Map or a table: from exponential to linear for stairs, coins and subarrays.