#sorting
6 articles
Sorting Algorithms, From Scratch
Build real intuition for sorting — from the O(n²) trio you can explain in your sleep to the O(n log n) workhorses that run in every standard library. Covers bubble, selection, insertion, merge, and quicksort with the concepts that actually matter.
The Top-K Elements Pattern
How a heap of size k gives you the k largest (or smallest, or most frequent) items in O(n log k) — and why a min-heap is the counterintuitive tool for finding the biggest things.
The Merge Intervals Pattern
Sort by start, sweep and merge — the one instinct that cracks meeting rooms, calendar conflicts, and range overlap problems in O(n log n). Master the overlap test and you'll recognize this pattern before you finish reading the problem statement.
Divide & Conquer
Split a problem into smaller subproblems, solve them independently, combine the results. This one mental model gives you merge sort, quickselect, the count-inversions trick, and Kadane's origin story — plus the intuition for why n log n is the price of sorting.
Cyclic Sort
The O(n) time, O(1) space trick for arrays that hold numbers in a known range 1..n: place each value at its natural index, then scan once for anything out of place. Missing numbers, duplicates, and corrupt pairs fall out as a natural consequence.
The Two Pointers Pattern
A sorted array and an O(n²) instinct — two indices, moving in tandem, collapse it to O(n). Here is the pattern, the tell that signals it, and every problem variant you will see.