Array
O(1) access by index
A row of values stored side by side in memory, each one reached by its position.
The twenty structures that most programs are built from, explained plainly: what each one is, how it works, and when to reach for it.
Each entry on this site starts with what the structure is, in plain language. Then it looks at how it works, what each operation costs, when to use it and when not to, and where you meet it in real programs. A short Python example and a diagram sit on every page. Sources are listed at the end of each page, so a reader can check the facts.
O(1) access by index
A row of values stored side by side in memory, each one reached by its position.
Last in, first out
A pile where you only ever touch the top. The last item added is the first one out.
O(1) lookup by key, on average
A table that finds a value by its key, not by searching. The key hashes to a bucket.
Nodes linked by pointers, O(1) insert at the head
A chain of nodes, each holding a value and a pointer to the next node.
First in, first out
A line where the first item in is the first item out. New items join at the back.
Double-ended queue, add or remove at either end
A queue with both ends open. Add or remove items at the left end or the right end.
Ordered tree, O(log n) search when balanced
A tree where smaller values go left and larger values go right, so search walks down one path.
Self-balancing tree, height kept within one
A binary search tree that rebalances itself with rotations, so its height stays logarithmic no matter the insertion order.
Self-balancing tree used by maps and sets
A binary search tree that paints each node red or black and rebalances with rotations, so its height stays logarithmic.
Wide, shallow tree built for disk and databases
A wide, shallow tree where each node holds many keys, so a search from disk reads few blocks.
Priority queue, smallest or largest always on top
A tree that always keeps the smallest or largest item at the top, ready to be taken next.
Prefix tree for words and autocomplete
A tree that stores words by their letters, one character per step, so words that share a beginning share the same path.
A hash table without values, for membership tests
A collection that remembers only whether something is in it. No values, no order, no duplicates.
Probabilistic membership, tiny memory, no false negatives
A tiny, fast way to ask whether something was seen before. A no is certain, a yes is only probably.
Nodes and edges, adjacency lists and matrices
A set of nodes joined by edges. The nodes are the things, and the edges are the relationships between them.
Union-Find in Graphs. LRU Cache, Skip List, Segment Tree, and Fenwick Tree in Specialized.