Top-K — Heap Is Not Always the Answer

A heap is the reflex answer to K-th largest problems, but when the whole array is already in memory, Quick Select is faster on average. The size-K heap and Quick Select mechanics, and how the shape of the data decides between them.

July 9, 2026 · 5 min read

Union-Find — Two Optimizations Make It Practically Constant

Union-Find gives each group a root representative and decides whether two elements share a group. The unoptimized version stretches find to O(N) on chain trees; path compression and union by rank make it practically constant.

July 4, 2026 · 5 min read

Topological Sort — Process Zero In-degree First

Kahn’s BFS for topological sort repeatedly takes nodes with zero in-degree, and cycle detection comes along without extra logic. The mechanism, the Course Schedule problems, and the selection criteria against DFS post-order.

July 3, 2026 · 5 min read

Sliding Window and Prefix Sum — When Monotonicity Decides

Subarray-sum problems collapse from O(N²) to O(N) along two paths — sliding window or prefix sum with a hash. Negative inputs or strict-equality conditions break monotonicity and shift the work from sliding window to prefix sum.

June 14, 2026 · 4 min read

Parametric Search — Binary-search the Answer

When the answer isn’t sitting in any array, you can still binary-search the answer itself. The parametric-search recipe — define the decision function, fix the direction of monotonicity, justify lo and hi.

June 13, 2026 · 5 min read