01Chapter 1: Divide and Conquer: The Idea Behind QuicksortQuicksort is one of the most widely used sorting algorithms. Its core idea is short: pick one element, put everything smaller on one side and everything larger on the other, then sort each side the same way. This chapter covers that idea using the general strategy of divide and conquer. Later chapte7 min read
02Chapter 2: Partitioning an Array Around a PivotPartitioning does most of the work in quicksort. The recursion only decides which ranges to sort next. The partition step moves the elements so that the recursion has something useful to work on. This chapter defines what a correct partition is, separate from any particular way of computing one. Wit5 min read
03Chapter 3: The Lomuto Partition SchemeThis chapter assumes you can read Python, trace index-based loops over arrays, and know what partitioning around a pivot means: after the step, smaller elements sit to the pivot's left and larger ones to its right. Here we look at one concrete way to do that, the Lomuto scheme. We cover its loop inv6 min read
04Chapter 4: Putting It Together: Recursive QuicksortThis chapter assumes you can read Python, that you understand how recursive calls use the call stack, and that you have the Lomuto partition function from the previous chapter. Here we take that partition step and build a complete, in-place sorting algorithm on top of it. Along the way, you will tra6 min read
05Chapter 5: In-Place but Not StableThis chapter assumes you already know the recursive Lomuto quicksort from the previous chapter. You should also be comfortable with Python tuples and lambdas, and know what Big-O means for memory as well as time.6 min read
06Chapter 6: How Fast Is Quicksort? Best, Average, and Worst CaseThis chapter works out how many operations quicksort performs. It assumes you know Big-O notation and recursion, and that you have read the earlier chapters on the Lomuto partition and recursive quicksort. The analysis uses that version: the last element is the pivot, and the keys are distinct. Dupl6 min read
07Chapter 7: When Quicksort Goes QuadraticThe previous chapter showed that quicksort takes O(n²) time when every partition is as lopsided as possible: one side gets n − 1 elements and the other gets none. This chapter covers which real inputs produce those splits, how to measure the problem, and why it matters beyond speed.6 min read
08Chapter 8: Choosing a Good PivotThis chapter assumes you can read the in-place Lomuto quicksort from earlier chapters, know why a sorted input pushes a last-element pivot into O(n²) time, and are comfortable with Big-O notation and recursion. Here we look at what makes a pivot "good" and compare the main strategies for picking one6 min read
09Chapter 9: Randomized QuicksortThis chapter assumes you have read the earlier chapters on the Lomuto partition scheme and on quicksort's best, average, and worst cases. You should be comfortable with Python, recursion, Big-O notation, and basic probability ideas such as expected value.6 min read
10Chapter 10: Median-of-Three Pivot SelectionThis chapter assumes you have worked through the Lomuto partition scheme, the recursive quicksort built on it, and the earlier analysis showing that a fixed last-element pivot degrades to O(n²) on sorted input. You should also be comfortable reading Python that swaps elements in place.6 min read
11Chapter 11: The Hoare Partition SchemeThis chapter assumes you have read the chapters on partitioning and the Lomuto scheme. It also assumes you can follow a recursive function in Python and know what O(n) means. Lomuto's scheme is easy to reason about because the pivot lands at its final index. Hoare's original 1961 scheme gives up tha6 min read
12Chapter 12: Three-Way Partitioning for Duplicate KeysEarlier chapters treated the pivot as one value that ends up in one slot. That assumption causes trouble when the input contains many copies of the same key. This chapter shows why two-way partitioning slows down on duplicates and how a three-way partition fixes it. It also covers what the fix costs6 min read
13Chapter 13: Bounding Recursion DepthThis chapter assumes you know the Lomuto partition scheme and the recursive quicksort built on it from earlier chapters. You should also know how the call stack works and why the worst-case running time is O(n²). The quicksort analysis so far has been about time. Here the subject is space: how many 6 min read
14Chapter 14: Switching to Insertion Sort for Small SubarraysThis chapter assumes you know the recursive quicksort from earlier chapters, the lomuto_partition function, how insertion sort works, and basic Big-O reasoning. The question here is practical. Quicksort is fast on large arrays, but most of its recursive calls handle tiny subarrays. Is quicksort st6 min read
15Chapter 15: Introsort: Quicksort in Production LibrariesEarlier chapters gave you several separate fixes for quicksort's weak spots. Better pivots lower the chance of bad splits. Recursing on the smaller side first keeps the stack shallow. Insertion sort handles tiny subarrays faster than further partitioning. None of these fixes guarantees O(n log n) ti6 min read
16Chapter 16: Quickselect: Finding the k-th Smallest ElementThis chapter assumes you have read the earlier chapters on the Lomuto partition scheme, randomized quicksort, and three-way partitioning. You should also be comfortable with Big-O notation and with summing a geometric series.6 min read