Blog

Notes on data structures & algorithms, system design, and things I learn along the way.

Learning DSA? Follow the structured path — ordered articles from recursion to dynamic programming.→
September 26, 2026Skip Lists: A Balanced Tree Built Out of Coin Flips5 min read

A sorted linked list with express lanes stacked on top. Search, insert and delete in O(log n) expected time, with no rotations and no rebalancing — just a random height for each new node. Why Redis sorted sets use one.

#DSA
September 24, 2026Binary Search on the Answer5 min read

The array isn't sorted. There is no array. You can still binary search — as long as you can write a yes/no question whose answers flip exactly once.

#DSA
September 24, 2026Longest Increasing Subsequence in O(n log n)5 min read

The O(n²) dynamic program is the one everyone learns. The faster version keeps one array of 'best endings' and binary searches it — and the array it builds is not the answer.

#DSA
September 24, 2026Reservoir Sampling: A Fair Sample From a Stream You Can't Count4 min read

Pick k items uniformly at random from a sequence of unknown length, in one pass, holding only k items. The algorithm is four lines; the proof is one induction step.

#DSA
September 19, 2026Minimum Spanning Trees: Kruskal, Prim, and the Cut Property5 min read

Connect every node for the least total weight. Two greedy algorithms that both work, the one theorem that explains why, and how to choose between them.

#DSA
September 18, 2026Fenwick Trees: Prefix Sums That Can Change4 min read

A prefix sum array answers range queries in O(1) but costs O(n) to update. A Fenwick tree makes both O(log n) using nothing but the lowest set bit of an index.

#DSA
September 14, 2026A* Pathfinding: Dijkstra With a Sense of Direction4 min read

One extra term in the priority function turns an exhaustive search into a guided one. What admissible and consistent heuristics mean, why they preserve optimality, and where A* degrades.

#DSA
September 13, 2026Prefix Sums and Difference Arrays: Trading Space for Constant-Time Queries4 min read

Precompute once, answer range queries in O(1). How prefix sums work, the sentinel zero that removes every edge case, difference arrays for range updates, and the 2D version.

#DSA
September 12, 2026Monotonic Stacks: The Pattern Behind Next Greater Element4 min read

A stack that refuses to hold out-of-order values turns a pile of quadratic problems into linear ones. How the invariant works, why the amortised cost is O(n), and the four questions it answers.

#DSA
July 16, 2026KMP String Matching: Search Without Backtracking5 min read

The naive substring search re-checks characters it's already seen and degrades to O(nm) on adversarial input. The Knuth-Morris-Pratt algorithm precomputes a failure table so the search pointer never moves backward, guaranteeing O(n + m).

#DSA

51 posts tagged DSA · page 3 of 6