#trees
11 articles
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.
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.
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.
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.
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.
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.
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.
DFS Patterns
Depth-first search is the backbone of cycle detection, flood fill, path enumeration, and clone graph — master the visited-set template, the 3-color trick, and when to reach for DFS over BFS.
BFS Patterns
Queue-driven level-by-level traversal and why breadth-first search is the only guaranteed way to find shortest paths in unweighted graphs. Templates, traps, and four worked problems.