Data Structures
Interactive guides to master the building blocks of algorithms.
Arrays & Strings
Static Arrays
A row of numbered boxes — fast to grab, fixed in size→
Dynamic Array
An array that grows automatically when it runs out of space→
Two Pointers
Two fingers tracing an array to solve problems in one pass→
Sliding Window
A picture frame scanning over an array to solve sub-array problems in \(O(n)\) time→
Prefix Sums
Pre-calculate a running total so you can sum any subarray in instant \(O(1)\) time→
Linked Lists
Singly Linked List
A chain of boxes — each one knows only where the next box is→
Doubly Linked List
A two-way chain — each node knows both its neighbour ahead and the one behind→
Circular Linked List
A chain with no end — the last link points back to the first→
Floyd's Cycle Detection
Catch a loop in a linked list using just two pointers and no extra memory→
Reversing a Linked List
Flip the entire chain so the last node becomes first — iteratively or recursively→
Stacks & Queues
Stack
A pile of plates — the last one you put on is the first one you take off→
Queue
A line of people waiting — the first one in is the first one served→
Deque
A line you can join or leave from either end — front or back, your choice→
Monotonic Stack
A stack that stays sorted — used to find the next bigger or smaller element fast→
Monotonic Queue
A queue that tracks the max or min of a sliding window in constant time→
Hash Tables
Trees
Binary Trees
A family tree where every parent has at most two children→
Binary Search Tree
A sorted binary tree — left is smaller, right is bigger→
BST Balancing
An unbalanced BST is just a slow linked list in disguise→
AVL Tree
A self-balancing BST that rebalances itself after every insert or delete→
Red-Black Tree
A self-balancing BST used inside Java's TreeMap and C++'s std::map→
Segment Tree
Answer range queries in \(O(\log n)\) with \(O(\log n)\) point updates→
Fenwick Tree (BIT)
Prefix sums in \(O(\log n)\) with elegant bit manipulation — simpler than a segment tree→
Trie (Prefix Tree)
Store strings by their prefixes — autocomplete in \(O(L)\) time→
N-ary Trees
When nodes can have any number of children — file systems, DOM, org charts→
Heaps & Priority Queues
Heaps
Always know the smallest (or largest) in \(O(1)\) — with \(O(\log n)\) updates→
Heap Sort
Sort in-place with guaranteed \(O(n \log n)\) — no extra memory needed→
Priority Queue Patterns
K-th largest, merge K lists, top-K frequent — solved with a small heap→
Two-Heap Pattern
Split the data in half — find the median in \(O(1)\) always→
Graphs
Graph Representation
How to store a map of cities and roads in memory→
Breadth-First Search
Explore a city map ring by ring — nearest neighbors first→
Depth-First Search
Follow one road as far as it goes before backtracking→
Topological Sort
Order cities so every one-way road points forward, never backward→
Union-Find (Disjoint Set Union)
Track connected groups — merge them near-instantly→
Minimum Spanning Tree
Connect all cities with the least total road construction cost→
Dijkstra's Algorithm
GPS for graphs — find the cheapest route from one node to all others→
Bellman-Ford Algorithm
Shortest paths with negative weights — and negative cycle detection→
Floyd-Warshall Algorithm
All-pairs shortest paths in one elegant triple loop→
Advanced / Specialized
Skip List
A linked list with express lanes — search in \(O(\log n)\) on average→
Bloom Filter
Ask 'is this here?' in \(O(1)\) — maybe yes, definitely no→
LRU Cache
Keep the most recent items fast — evict the forgotten ones→
Sparse Table
Answer range minimum queries in \(O(1)\) after \(O(n \log n)\) setup→
Suffix Array & LCP Array
Sort every suffix of a string — unlock powerful substring queries→