#data-structures
24 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
The two simplest constrained collections in CS — and the ones that show up everywhere once you know what to look for. Understand LIFO vs FIFO, how the call stack works, and when each structure is exactly the right tool.
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
The graph data structure models the real world — maps, social networks, dependencies — better than any other. Learn how nodes and edges work, how to represent them, and how BFS and DFS let you actually do something useful with them.
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.
Union-Find (Disjoint Set Union)
The near-magic data structure for connectivity queries — are these two nodes in the same component? Nearly O(1) per operation with union by rank and path compression. Kruskal's MST, redundant connections, account merging, and more.
Tries (Prefix Trees)
The data structure powering autocomplete, spell-check, and IP routing — a tree where each edge is a character and every path from the root spells a prefix. Insert, search, and prefix queries all run in O(L) on word length alone, completely independent of how many words you store.
Strings
Strings look like simple text, but they hide a brutal trap: naive concatenation in a loop is O(n²). Learn why, how encoding actually works, and the handful of patterns — sliding window, two pointers, hashing — that solve 80% of string interview problems.
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
The definitive guide to the LRU cache — how to combine a hash map and a doubly linked list to get O(1) get and put, why neither structure alone is enough, and how to walk the full implementation in an interview.
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 give you O(log n) prefix-sum queries AND point updates in ~10 lines of code — leaner and faster in practice than a segment tree for this exact job. Learn the lowbit trick, build the tree, and know when a BIT beats everything else.
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
A probabilistic set that answers "definitely not" or "maybe yes" using a bit array and k hash functions — orders of magnitude smaller than a hash set, with a tunable false-positive rate and mathematically guaranteed zero false negatives.
Balanced BSTs (AVL & Red-Black Trees)
Self-balancing trees fix the degenerate-BST problem by keeping height O(log n) guaranteed — which is why Java's TreeMap, C++'s std::map, and every ordered set in the standard library runs on one under the hood.
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 one rule — first in, first out — and that rule shows up everywhere from BFS to task schedulers. Learn how to get O(1) on both ends without the hidden tax of a naive array.
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
The heap data structure gives you O(1) peek at the min (or max) and O(log n) insert and extract — the exact shape you need for scheduling, K-way merging, and the top-K pattern that shows up everywhere in systems interviews.
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
The data structure that models everything connected — social networks, road maps, dependency chains, and more. Master representations, traversals, and the "model it as a graph" reframe that unlocks whole categories of problems.
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.