Module M13 · 13 of 35 in teaching order · Intermediate
Sorting
Stability, in-place sorting, the classic algorithms and what built-in sorts actually do.
Lessons
What a stable sort guarantees, why it matters for multi-key sorting, what "in place" really means, and which classic and built-in sorts have each property.
The three quadratic sorts side by side: how each works, exact comparison and write counts, stability, adaptivity, and where insertion sort still runs in real libraries.
How top-down merge sort works: recursive splitting, stable merging with one buffer, the call stack, and why it is O(n log n) in every case. Four languages, 3D.
Quicksort with the Lomuto partition and a middle pivot: the partition invariant, the recursion stack, O(n log n) on average, O(n²) at worst, and the fixes.
Timsort in Python and Java, dual-pivot quicksort for Java primitives, introsort in .NET and std::sort: what each guarantees, and how runs and galloping work.
Topics this module covers
The full module scope. Topics without a lesson above are not written yet.
- stability
- in-place
- bubble
- selection
- insertion
- shell
- merge
- quick
- partition
- heap
- counting
- radix
- bucket
- Timsort
- introsort
- built-ins
- comparison