#sorting
6 articles
Sorting Algorithms, From Scratch
Build real sorting intuition — from the O(n²) trio to the O(n log n) workhorses: bubble, selection, insertion, merge, and quicksort.
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
Master the merge intervals pattern: sort by start, sweep once, and crack meeting rooms, calendar conflicts, and range overlap problems in O(n log n).
Divide & Conquer
Split, solve, combine: divide and conquer through merge sort, quickselect, and counting inversions — plus the master theorem and when an O(n) loop wins.
Cyclic Sort
Cyclic sort: the O(n) time, O(1) space pattern for arrays holding values 1..n — swap each value to its home index, then scan for missing numbers and duplicates.
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.