The Sorting Problem
Formal statement of the sorting problem and the criteria to evaluate sorting algorithms: complexity, comparisons, swaps, stability, and memory.
Bubble Sort
Bubble sort, inversions, sentinel optimization, and bidirectional (cocktail) bubble sort with traces and measurements.
Insertion Sort
Direct insertion sort, why it is adaptive on nearly sorted data, binary insertion sort, and empirical measurements.
Selection Sort
Direct selection sort, why it performs at most n - 1 swaps, why it is not stable, and when its few swaps make it useful.
Quicksort
Partitioning, pivot selection with median-of-three, average vs. worst-case analysis, and practical engineering improvements.
Beyond Quadratic Sorting
Mergesort, the Omega(n log n) lower bound for comparison sorting, and what real sorting libraries use.
Comparing Sorting Algorithms
Head-to-head complexity and empirical benchmarks of sorting algorithms, external sorting, and how to choose one in practice.
Summary
Chapter 2 summary: sorting criteria, complexity table at a glance, and practical selection guidelines.
Exercises
Exercises with solutions on simple sorts, Quicksort, merging, lower bounds, and algorithm selection.
Proofs
Formal proofs for Chapter 2: correctness of sorting algorithms and the n log n comparison lower bound.
References
Textbooks and original papers on sorting algorithms.