liveBook · Manning

Chapter 4: Quicksort

What you will learn in chapter 4 of Grokking Algorithms, Second Edition

The introduction presents divide and conquer as a reusable recursive technique to consider when familiar algorithms do not solve a new problem.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction presents divide and conquer as a reusable recursive technique to consider when familiar algorithms do not solve a new problem.

Key terms: divide and conquer, D&C, recursion

4.1 Divide and conquer

The section teaches divide and conquer through a square-plot problem and a recursive array-sum example.

Key terms: D&C, base case, recursive call, largest square size, farm segment, sum function, array

4.2 Quicksort

This section explains how quicksort recursively partitions and recombines an array, then uses inductive reasoning to show why it works for arrays of any size.

Key terms: base case, empty arrays, pivot, partitioning, sub-arrays, quicksort, inductive proofs, inductive case

4.3 Big O notation revisited

This section compares common sorting run times and introduces quicksort’s pivot-dependent average and worst cases.

Key terms: pivot, selection sort, merge sort, quicksort, worst case, average case, example times, 10 operations per second, run times

4.4 Merge sort vs. quicksort

The section explains why algorithms with the same Big O time can differ in practice, using quicksort and merge sort as an example.

Key terms: O(n), constant, big O notation, binary search, simple search, log time, quicksort, merge sort, O(n log n), average case

4.5 Average case vs. worst case

This section shows how pivot choice affects quicksort’s call-stack depth and uses that depth to explain its best-, worst-, and average-case running times.

Key terms: pivot, sub-arrays, call stack, base case, O(n), O(log n), O(n log n), O(n2), height of the call stack, random element

4.6 Recap

Recaps divide and conquer, quicksort’s pivot choice and average runtime, and why algorithms with the same Big O runtime can differ in speed.

Key terms: D&C, base case, quicksort, pivot, average run time, O(n log n), big O running time, constant, merge sort, simple search

Concepts explained in this chapter

← Chapter 3: Recursion Chapter 5: Hash tables →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.