Data structures explained
The shapes data is stored in, and why the right shape turns a slow question into a fast one.
Every data structures concept
Merkle trees
Hash the hashes, and prove one leaf without the rest.
OPEN LESSON
Arrays
One block of memory, instant access by index, and costly inserts in the middle.
OPEN LESSON
Gap buffers
The array with a hole at the cursor that makes typing cheap.
OPEN LESSON
Deques
A queue open at both ends: add or remove at the front or the back in one step.
OPEN LESSON
Circular buffers
A fixed array reused as an endless loop, with a head and a tail that wrap round.
OPEN LESSON
Hash sets
A bag of unique keys that can tell you in one step whether an item is inside.
OPEN LESSON
Binary trees
Nodes with a left and a right child, the shapes they form and how tall they get.
OPEN LESSON
Heaps
A tree in an array that keeps its smallest value on top through inserts and removals.
OPEN LESSON
Priority queues
A queue where the most urgent item leaves first, and the heap that makes it fast.
OPEN LESSON
Tries
A tree of letters where words that start the same share the same path.
OPEN LESSON
Fenwick trees
Running totals that survive updates, using the lowest 1 bit of each index.
OPEN LESSON
Adjacency list vs adjacency matrix
Two ways to store a graph, and what each costs in memory and lookups.
OPEN LESSON
Directed acyclic graphs (DAGs)
One-way arrows and no loops: the shape of anything that has dependencies.
OPEN LESSON
Bloom filters
A row of bits that says “definitely not” or “probably yes” without storing anything.
OPEN LESSON
K-d trees
Cut space in half, again and again, to find the nearest point without checking them all.
OPEN LESSON
Rope data structure
A tree of small text pieces that keeps edits to huge files cheap.
OPEN LESSON
Suffix arrays
Sort every ending of a text once, then find any word in it by binary search.
OPEN LESSON
Splay trees
A search tree that rotates whatever you just used up to the root.
OPEN LESSON