liveBook · Manning

Pivot

As explained in Object-Oriented Software Design in C++

A pivot is an element selected by a partition-based sorting algorithm to divide a sequence into smaller regions.

A pivot is an array element chosen by quicksort to divide a sequence into two subarrays. After partitioning, it occupies its final sorted position. section 15.6

Partitioning around a pivot proceeds as follows:

  • Choose an element, commonly near the middle, and move it temporarily to the rightmost position. section 15.6.2
  • Scan inward with indexes i and j, skipping values already correctly placed on the left or right. section 15.6.2
  • Swap misplaced values while i remains left of j; stop when the indexes cross. section 15.6.2
  • Swap the pivot into position, leaving values less than or equal to it on the left and greater values on the right. section 15.6.2

Pivot 52

Choosing 52 as the pivot rearranges the array so values less than or equal to 52 lie to its left and greater values lie to its right. Quicksort then processes both regions recursively. section 15.6.2

Figure 15.11 The quicksort algorithm in action as it sorts an array. The circled values are the chosen pivot elements that create the subarrays on both sides after partitioning. The rectangles enclose the subarrays to be quicksorted recursively. In each line, the shaded subarray is the one actively being sorted. The values in bold are already in their correct places in the final sorted array. Note that the chosen pivot elements are always already in their correct places after partitioning.

Trace pivot choices, active subarrays, completed positions, and recursive partitioning across a full quicksort run. section 15.6.1

How Object-Oriented Software Design in C++ covers it

How deep it goes
Explains selection, temporary placement, bidirectional scanning, swapping, and final placement, but does not compare pivot-selection strategies.
Examples
Demonstrates pivots using values 16, 7, 71, 65, 52, and 33 in array-partitioning traces.
What it assumes
Assumes arrays and recursive sorting, while defining pivot selection and partitioning through concrete procedures.
What you can do after
Build it from scratch by implementing quicksort partitioning with indexes, swaps, recursive calls, and sortedness verification.
How it connects
Connects pivots with quicksort, partitioning, recursion, arrays, subarrays, and base cases.

Also explained in

Compare how 4 books explain pivot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Object-Oriented Software Design in C++. The section links point to the parts of the book it draws on.