// TOPIC

#sorting

6 articles

Beginner
01

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.

#sorting#algorithms#fundamentals
12 min
◆◆IntermediateAmazonGoogle
02

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.

#heaps#priority-queues#hash-maps
11 min
◆◆IntermediateAmazonGoogle
03

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.

#intervals#sorting#greedy
10 min
◆◆IntermediateGoogleAmazon
04

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.

#divide-and-conquer#sorting#recursion
12 min
◆◆IntermediateAmazonMeta
05

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.

#arrays#sorting#patterns
10 min
◆◆IntermediateAmazonMeta
06

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.

#two-pointers#arrays#sorting
10 min