Data Structure Visualizations
Data structure visualizations make the invisible part visible: not the values a structure holds, but the deal it strikes — which operation it makes fast and which one it quietly makes slow. This collection animates the core data structures step by step, each synced to its real code, so you can watch a hash collision pile up, a tree search descend, or a heap bubble a new minimum to the top.
There is no best data structure, only a best one for what you keep doing. A stack makes the most recent item instant and everything else unreachable. A hash table finds any key in one step but forgets every notion of order. A balanced tree keeps everything sorted and pays a logarithm for the privilege. Pick a structure and you are really picking which operations you want cheap — that single trade is what these animations are built to show.
How to Read a Data Structure
Open any visualization, run an operation, and watch three things:
- What is it fast at, and what did that cost? A stack pushes and pops in O(1) but can only touch its top. A hash table searches in O(1) on average but stores nothing in order. Every speed is bought somewhere.
- How does it find things? This is the real dividing line. A linked list follows pointers one node at a time. A hash table computes an index from the key. A binary search tree compares and descends left or right. A heap doesn't search at all — it only ever surrenders its top.
- Does it keep order, and which kind? None (hash table), insertion order (linked list, stack, queue), full sorted order (BST), or just-enough order to know the extreme (heap). Ordering is exactly what costs the logarithm.
Data Structure Operation Comparison
Average, worst-case, and amortized costs are marked; the hash table and BST degrade to O(n) in their worst cases (every key colliding, or an unbalanced tree). Linked-list O(1) assumes you already hold the node or predecessor the operation needs; finding it is the O(n) search. Stack and queue O(1) assumes an implementation that is cheap at both ends — the Queue lesson's list-backed pop(0) is O(n).
| Structure | Search | Insert | Delete | Ordering |
|---|---|---|---|---|
| Array list | O(n) · O(1) by index | O(1) amortized append · O(n) at i | O(n) at i | index order |
| Stack | — | O(1) push | O(1) pop | LIFO, top only |
| Monotonic stack (next greater) | O(n) full scan | O(1) push | O(1) pop | non-increasing waiting candidates |
| Queue | — | O(1) enqueue | O(1) dequeue | FIFO, ends only |
| Linked list | O(n) | O(1) after a known node | O(1) given the predecessor | insertion |
| Doubly linked list | O(n), from either end | O(1) at a node | O(1) given the node | insertion, walkable both ways |
| Circular linked list | O(n), from any node | O(1) after a known node | O(1) given the predecessor | insertion, wraps to the head |
| Hash table | O(1) avg | O(1) avg | O(1) avg | none |
| Binary search tree | O(log n) avg | O(log n) avg | O(log n) avg | sorted |
| AVL tree | O(log n) worst | O(log n) worst | O(log n) worst | sorted, height-balanced |
| Red-black tree | O(log n) worst | O(log n) worst | O(log n) worst | sorted, color-balanced |
| Trie | O(L) | O(L) | O(L) | prefix paths |
| Heap | — | O(log n) | O(log n) min/max | partial (priority) |
| Union-Find | find root: ~O(1) amortized (union by rank + path compression) | union: ~O(1) amortized | — | disjoint sets |
| Graph (list / matrix) | edge: O(deg(u)) / O(1) | edge: O(1) / O(1) | edge: O(deg(u)) / O(1) | adjacency |
The table reads as a ladder of trades. Stacks and queues buy O(1) by refusing random access. Hash tables buy O(1) search by throwing away order. Trees buy ordered O(log n) by giving up the array's O(1) indexing. Each row gains exactly what the row above it gave up.
A Recommended Learning Order
Start with the array list, the contiguous baseline every other structure reacts against: it buys O(1) indexing with O(n) shifts and the occasional double-and-copy when its backing array fills. Then the stack and the queue — the two structures defined by what they won't let you do. LIFO and FIFO are restrictions, and seeing how much you get from so little is an early lesson. Right after the ordinary stack, learn the monotonic stack: it turns the same push/pop interface into an O(n) scanning pattern by keeping only unresolved candidates in value order, and makes amortized analysis visible because every index enters once and leaves at most once. Then the linked list, the array list's opposite: a pointer chain that makes O(1) insertion possible and O(n) lookup unavoidable, and the place "this points to that" stops being abstract. Its two variants sharpen the pointer discipline. The doubly linked list spends a second pointer per node and gets back O(1) deletion and a walk in either direction; the circular linked list bends the tail's null into a link back to the head, which makes round-robin rotation natural and turns "have I wrapped past the start?" into the loop's real boundary question.
Next, the hash tables — chaining and probing. They deliver O(1) by computing where a key belongs instead of looking for it, and the two versions show the two honest answers to the one hard question: what do you do when two keys want the same slot? Before the search trees, tree basics pins down the vocabulary — root, leaf, height, depth, and the three traversal orders — on one small tree, so the lessons that follow can spend their time on structure instead of terminology. Then the binary search tree, which keeps keys in sorted order so search can halve its way down in O(log n) without an array's expensive inserts. Follow it with the AVL tree to see what the plain BST leaves unresolved: after each insertion, stored heights and LL, RR, LR, or RL rotations keep the worst-case search path logarithmic. The red-black tree keeps the same worst-case bound with a looser, color-based invariant: the uncle's color chooses between recoloring upward and a one- or two-rotation local repair.
The trie is the string-specialist after the BST. It trades comparison-based branching for one edge per character, stores shared prefixes once, and makes prefix queries a native operation. The graph representation lesson is the bridge from data structures to traversal: the same edges become either neighbor rows or a square matrix, and that storage choice decides whether edge lookup or sparse iteration is cheap. Union-Find asks a different question than every structure above — not "where is my key?" but "are these two in the same group?" — and answers it in near-constant amortized time once union by rank keeps its trees short and path compression flattens them; it is the engine behind cycle detection in Kruskal's minimum spanning tree. Finish with the heap, which gives up full ordering and keeps only enough to hand you the minimum or maximum in O(log n) — the structure behind every priority queue and the engine inside heap sort.
All Data Structure Visualizations
Pick any structure below to open its interactive player — run operations, change the input, and watch the code highlight move in lockstep with the animation.