#data-structures
25 articles
What Is a Data Structure?
A data structure is a deal you strike — you give up something to make one operation fast. Here is the big picture before you dive into any of them.
Stacks and Queues: Order Matters
Learn LIFO vs FIFO, how the call stack works, and when a stack or queue is exactly the right tool — the two simplest constrained collections in CS.
Trees: When Data Branches
Move beyond flat lists and discover why trees power everything from file systems to databases. Learn nodes, roots, leaves, height, and how a balanced tree buys you O(log n) on a silver platter.
Graphs: Everything Is Connected
Graphs model maps, social networks, and dependencies. Learn how nodes and edges work, how to represent them, and what BFS and DFS unlock.
Choosing the Right Data Structure
The meta-skill every engineer needs — a decision framework that maps your dominant operation to the right structure, so you stop guessing and start choosing deliberately.
Skip Lists: The Structure Redis Chose Over Balanced Trees
Skip lists replace tree rotations with coin flips: expected O(log n) search, insert, and delete in ~40 lines. Why Redis, LevelDB, and Java picked them.
Union-Find (Disjoint Set Union)
Union-Find (disjoint set union) answers 'are these two nodes connected?' in near-constant time. Master path compression, union by rank, and Kruskal's MST.
Tries (Prefix Trees)
How tries (prefix trees) power autocomplete and spell-check — insert, search, and prefix queries all run in O(L) on word length, not dictionary size.
Strings
Strings are immutable arrays hiding an O(n²) concatenation trap. Learn the sliding window, two-pointer, and hashing patterns that crack string interviews.
Segment Trees
Segment trees answer range queries AND handle point or range updates in O(log n) — the structure to reach for when prefix sums aren't enough and you need both reads and writes at scale.
LRU Cache
Implement an LRU cache with O(1) get and put: hash map plus doubly linked list, full Python code, eviction mechanics, and the interview traps.
Hash Sets
A hash set is a hash table with the values ripped out — pure O(1) membership, dedup, and "have I seen this?" tracking. Master it and a whole class of O(n²) problems collapse to O(n).
Fenwick Trees (Binary Indexed Trees)
Fenwick trees deliver O(log n) prefix sums and point updates in ~10 lines of code. Master the lowbit trick and know when a BIT beats a segment tree.
Deques (Double-Ended Queues)
A deque gives you O(1) push and pop from both ends — and the sliding-window-maximum trick that turns O(n²) brute-force problems into clean O(n) solutions.
Bloom Filters
How a bloom filter answers 'definitely not' or 'maybe yes' in ~10 bits per item: the math behind 1% fpp, working Python code, and production uses.
Balanced BSTs (AVL & Red-Black Trees)
Balanced BSTs keep height O(log n) on any insert order. See how AVL and red-black rotations work, and why Java TreeMap and C++ std::map run on them.
Stacks
The stack data structure explained from first principles — LIFO semantics, O(1) push and pop, and why it shows up everywhere from your call stack to balanced-parentheses checkers.
Queues and Deques
The queue data structure enforces first in, first out — powering BFS and schedulers. Learn why list.pop(0) costs O(n) and how to get true O(1).
Linked Lists
The linked list data structure explained from first principles — nodes, pointers, O(1) insert at a known position, and why arrays still win most of the time.
Heaps and Priority Queues
Learn how the heap data structure delivers O(1) peek and O(log n) push and pop — the engine behind priority queues, top-K queries, and K-way merges.
Hash Tables
The interview MVP. How hash functions turn arbitrary keys into O(1) lookups, what actually happens during a collision, and why "just use a hash map" is usually the right instinct.
Graphs
Learn the graph data structure: adjacency lists vs matrices, BFS and DFS traversal, and the grid-as-graph reframe that cracks whole problem categories.
Binary Trees and Traversals
Master binary tree traversal — inorder, preorder, postorder, and level-order — and the recursive mindset that makes dozens of tree problems click instantly.
Binary Search Trees
The left<node<right invariant gives you O(log n) search, insert, and delete — until the tree degenerates into a linked list. Here's the full picture, including why inorder traversal is a free sort.
Arrays
The data structure everything else is built on. Why arr[i] is instant, why inserting in the middle hurts, and the handful of patterns that turn arrays into interview wins.