G27
Self-checkedTier 1 14 min readalgo.sorting-quick

Quicksort

Quicksort: partition around a pivot, sort the two sides in place. The partition and its invariant, the recurrence for any split, the worst case n(n-1)/2 on sorted input, the balanced best case, the exact average 2(n+1)H_n - 4n comparisons (about 1.39 n log2 n), why any constant-fraction split is still n log n, randomised pivots, the stack depth and the smaller-part-first rule, and behaviour with equal keys.

Why it exists

Quicksort is the sorting method used most in practice: it sorts in place, needs only a small stack, and its inner loop is very short, so on average it beats merge sort and heap sort by a constant factor. Its weakness is a worst case of Θ(n2)\Theta(n^2) on unlucky inputs, and GATE tests exactly this contrast: which inputs are bad, what the recurrence is, and why the average case is still nlog⁡nn \log n.

Prerequisites

You need divide and conquer and the recurrence T(n)=T(k)+T(n−k−1)+Θ(n)T(n) = T(k) + T(n - k - 1) + \Theta(n) (divide and conquer).

Precise definitions

Partition. Choose one key, the pivot, and rearrange a range so that every key to the left of the pivot's final position is ≤\le the pivot and every key to the right is >> it (Lomuto) or ≥\ge it (Hoare). After a Lomuto partition (below) the pivot is in its final sorted position; Hoare's original partition instead returns a split point, with every key on the left ≤\le every key on the right.

Quicksort. Partition the range, then sort the part left of the pivot and the part right of the pivot recursively. There is no merge step: when both recursive calls return the range is sorted.

Lomuto partition (used on this page). The pivot is the last key ahia_{hi}. A boundary ii keeps the invariant: positions lo..ilo..i hold keys ≤\le pivot, positions i+1..j−1i + 1..j - 1 hold keys >> pivot, positions j..hi−1j..hi - 1 are unexamined. Scan jj from lolo to hi−1hi - 1; if aj≤a_j \le pivot, increase ii and swap aia_i with aja_j. At the end swap the pivot into position i+1i + 1. It makes exactly hi−lohi - lo comparisons.

Hoare partition (the original). Two indices start at the two ends and move towards each other; the left one stops at a key ≥\ge pivot, the right one at a key ≤\le pivot, the two keys are swapped, and so on until the indices cross. It splits evenly when many keys are equal, because both indices stop on keys equal to the pivot.

Randomised quicksort. Choose the pivot uniformly at random among the keys of the range (for example swap a random key to the end first). The running time then depends on the random choices, not on the input order.

How it works

A real run. The animation sorts 6,3,8,1,7,2,5,46, 3, 8, 1, 7, 2, 5, 4 with exactly the code shown. In each partition the pivot is the last key; the key under comparison is marked; whenever a key is not larger than the pivot it is swapped to the growing left part; at the end the pivot is swapped into its final place (green).

Quicksort with the last element as pivot (Lomuto partition)

Real run

C source

1#include <stdio.h>
2
3static void swap(int *x, int *y) {
4 int t = *x;
5 *x = *y;
6 *y = t;
7}
8
9/* partitions a[lo..hi] around the pivot a[hi]; returns the final position of the pivot */
10static int partition(int a[], int lo, int hi) {
11 int pivot = a[hi];
12 int i = lo - 1;
13 for (int j = lo; j < hi; j++) {
14 if (a[j] <= pivot) {
15 i++;
16 swap(&a[i], &a[j]);
17 }
18 }
19 swap(&a[i + 1], &a[hi]);
20 return i + 1;
21}
22
23void quicksort(int a[], int lo, int hi) {
24 if (lo < hi) {
25 int p = partition(a, lo, hi);
26 quicksort(a, lo, p - 1);
27 quicksort(a, p + 1, hi);
28 } else if (lo == hi) {
29 }
30}

Array a (faded = outside the current call)

6
0
3
1
8
2
1
3
7
4
2
5
5
6
4
7

State

pivot = 0, i = -1, j = 0, comparisons = 0, swaps = 0

Blue = the position this step is working on, amber = a position being compared, red = positions just swapped, green = finished or in its final place, a filled blue cell = a value just placed, faded = not part of the structure at this step.

Step 1

Sort 6, 3, 8, 1, 7, 2, 5, 4 with quicksort.

1 / 37
The array 6, 3, 8, 1, 7, 2, 5, 4 is set up by hidden driver code. partition(), quicksort() and swap() are the exact code that runs. Green cells are in their final positions. Produced by: real execution: every array, stack, matrix and list in the picture is read from the running program's memory at each step. Apple clang version 21.0.0 (clang-2100.1.1.101). gcc -O0 -o prog prog.c && ./prog

Where the cost is. One partition of nn keys makes n−1n - 1 comparisons. If it splits the range into parts of sizes kk and n−1−kn - 1 - k, then T(n)=T(k)+T(n−1−k)+Θ(n).T(n) = T(k) + T(n - 1 - k) + \Theta(n). Everything depends on the splits:

  • Worst case: always k=0k = 0 (the pivot is the smallest or the largest key): T(n)=T(n−1)+Θ(n)=Θ(n2)T(n) = T(n - 1) + \Theta(n) = \Theta(n^2), exactly n(n−1)/2n(n-1)/2 comparisons. For the last-element pivot this happens on sorted and on reverse sorted input, and with the Lomuto partition above (which sends keys equal to the pivot to the left) also when all keys are equal.
  • Best case: always k=⌊(n−1)/2⌋k = \lfloor (n-1)/2 \rfloor (the pivot is the median): T(n)=2T(n/2)+Θ(n)=Θ(nlog⁡n)T(n) = 2T(n/2) + \Theta(n) = \Theta(n \log n).
  • Any constant-fraction split: if every split is at most 9:19 : 1, then T(n)=T(n/10)+T(9n/10)+nT(n) = T(n/10) + T(9n/10) + n. The recursion tree has depth between log⁡10n\log_{10} n and log⁡10/9n\log_{10/9} n and every level costs at most nn, so T(n)=Θ(nlog⁡n)T(n) = \Theta(n \log n). A split that is not perfect but is proportional is still fast.
  • Average case: for a random order of distinct keys the expected number of comparisons is exactly C(n)=2(n+1)Hn−4n≈1.39 nlog⁡2n,Hn=1+12+⋯+1n,C(n) = 2(n + 1) H_n - 4n \approx 1.39\, n \log_2 n,\qquad H_n = 1 + \tfrac12 + \cdots + \tfrac1n, so Θ(nlog⁡n)\Theta(n \log n), only about 39%39\% more comparisons than the best case.

Why the average is 2(n+1)Hn−4n2(n+1)H_n - 4n. Call the keys z1<z2<⋯<znz_1 < z_2 < \cdots < z_n in sorted order. Two keys ziz_i and zjz_j are compared at most once, and they are compared exactly when one of them is the first pivot chosen among zi,zi+1,…,zjz_i, z_{i+1}, \ldots, z_j (if a key strictly between them is chosen first, they are separated and never meet). For a random order each of these j−i+1j - i + 1 keys is equally likely to be first, so the probability is 2/(j−i+1)2/(j - i + 1). Summing over all pairs with d=j−i+1d = j - i + 1 from 22 to nn (there are n+1−dn + 1 - d pairs with this dd): C(n)=∑d=2n(n+1−d)2d=2(n+1)(Hn−1)−2(n−1)=2(n+1)Hn−4n.C(n) = \sum_{d=2}^{n} (n + 1 - d) \frac{2}{d} = 2(n + 1)(H_n - 1) - 2(n - 1) = 2(n + 1)H_n - 4n . The same value solves the recurrence C(n)=n−1+2n∑k=0n−1C(k)C(n) = n - 1 + \frac{2}{n} \sum_{k=0}^{n-1} C(k).

Measured. The program below counts the comparisons of this very code on sorted, reversed, all-equal and random inputs. The random column is the average of 400400 random orders and is close to the exact expectation.

#include <stdio.h>
 
static long cmps;
 
static void swap(int *x, int *y) { int t = *x; *x = *y; *y = t; }
 
static int partition(int a[], int lo, int hi) {
    int pivot = a[hi], i = lo - 1;
    for (int j = lo; j < hi; j++) {
        cmps++;
        if (a[j] <= pivot) {
            i++;
            swap(&a[i], &a[j]);
        }
    }
    swap(&a[i + 1], &a[hi]);
    return i + 1;
}
 
static void quicksort(int a[], int lo, int hi) {
    if (lo < hi) {
        int p = partition(a, lo, hi);
        quicksort(a, lo, p - 1);
        quicksort(a, p + 1, hi);
    }
}
 
static long run(int a[], int n) {
    cmps = 0;
    quicksort(a, 0, n - 1);
    for (int i = 1; i < n; i++) if (a[i - 1] > a[i]) return -1;
    return cmps;
}
 
int main(void) {
    static int a[1024];
    int ns[] = {16, 64, 256, 1024};
    unsigned s = 99;
    printf("%5s %9s %9s %9s %12s\n", "n", "sorted", "reversed", "all-equal", "random-total");
    for (int q = 0; q < 4; q++) {
        int n = ns[q];
        for (int i = 0; i < n; i++) a[i] = i;
        long c1 = run(a, n);
        for (int i = 0; i < n; i++) a[i] = n - i;
        long c2 = run(a, n);
        for (int i = 0; i < n; i++) a[i] = 7;
        long c3 = run(a, n);
        long total = 0;                                   /* 400 random permutations: Fisher-Yates with a simple generator */
        for (int trial = 0; trial < 400; trial++) {
            for (int i = 0; i < n; i++) a[i] = i;
            for (int i = n - 1; i > 0; i--) { s = s * 1103515245u + 12345u; int j = (int)((s >> 8) % (unsigned)(i + 1)); swap(&a[i], &a[j]); }
            total += run(a, n);
        }
        printf("%5d %9ld %9ld %9ld %12ld\n", n, c1, c2, c3, total);
    }
    return 0;
}
    n    sorted  reversed all-equal random-total
   16       120       120       120        20509
   64      2016      2016      2016       144000
  256     32640     32640     32640       850120
 1024    523776    523776    523776      4521100

Comparisons of quicksort, measured: start

Computed by a script, not typed
nsortedreversedall equalrandom (average of 400)2(n+1)H_n - 4nn log2 n
16
64
256
1024

Step 0

Quicksort with the last element as pivot and the partition of this page, on four kinds of input. The random column is the average over 400 random orders of the keys.

0 / 4
computed by script: the quantities are measured by running C, or evaluated, one row at a time. python3 scripts/gen-algo-sort2-traces.py

Choosing the pivot. A fixed rule (first, last) is defeated by sorted input, which is common in practice. Remedies: choose a random key (expected 2(n+1)Hn−4n2(n+1)H_n - 4n comparisons for every input, because the randomness is in the algorithm), or the median of three (first, middle, last keys), or the true median found in linear time by the median-of-medians method (divide and conquer applications), which makes the worst case Θ(nlog⁡n)\Theta(n \log n) at the price of a large constant.

Stack space. The recursion depth is the height of the recursion tree: Θ(log⁡n)\Theta(\log n) for balanced splits and n−1n - 1 for the worst case. The space of quicksort is therefore O(log⁡n)O(\log n) on average but O(n)O(n) in the worst case, unless the algorithm recurses on the smaller part and handles the larger part in a loop (tail-call elimination): each recursive call then handles at most half of the keys, so the depth is at most ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1, whatever the input.

Equal keys. The Lomuto partition above sends equal keys to the left, so a range of equal keys splits 0:(n−1)0 : (n - 1) every time and costs Θ(n2)\Theta(n^2) (the table shows n(n−1)/2n(n-1)/2 for all-equal input). Hoare's partition stops on equal keys and splits such a range in the middle. The three-way partition (keys <<, ==, >> the pivot) puts all keys equal to the pivot in place at once, which makes all-equal input take Θ(n)\Theta(n).

Properties. In place (apart from the stack); not stable (the partition swaps keys across the pivot, over equal keys); not adaptive in the sense of insertion sort (sorted input is the worst case for the simple pivot rules); average Θ(nlog⁡n)\Theta(n \log n), worst case Θ(n2)\Theta(n^2). Practical versions switch to insertion sort for ranges below about ten keys.

Worked examples

EX 1One partition

Easy

6,3,8,1,7,2,5,46, 3, 8, 1, 7, 2, 5, 4 with pivot 44 (the last key). Scan: 6>46 > 4 stays; 3≤43 \le 4: i=0i = 0, swap a0,a1a_0, a_1: 3,6,8,1,7,2,5,43, 6, 8, 1, 7, 2, 5, 4; 8>48 > 4; 1≤41 \le 4: i=1i = 1, swap a1,a3a_1, a_3: 3,1,8,6,7,2,5,43, 1, 8, 6, 7, 2, 5, 4; 7>47 > 4; 2≤42 \le 4: i=2i = 2, swap a2,a5a_2, a_5: 3,1,2,6,7,8,5,43, 1, 2, 6, 7, 8, 5, 4; 5>45 > 4. Finally swap the pivot into position i+1=3i + 1 = 3: 3,1,2,4,7,8,5,63, 1, 2, \mathbf{4}, 7, 8, 5, 6. Seven comparisons; the pivot 44 is in its final place, with 33 keys to its left and 44 to its right.

EX 2Comparisons on sorted input

Easy

For n=1000n = 1000 keys already in increasing order, with the last key as pivot, every partition peels off one key: 999+998+⋯+1=499 500999 + 998 + \cdots + 1 = 499\,500 comparisons (the table's rule n(n−1)/2n(n-1)/2), against about 1.39⋅1000⋅9.97≈13 8001.39 \cdot 1000 \cdot 9.97 \approx 13\,800 on a random order. The recursion depth is 999999.

EX 3A lopsided but proportional split

Medium

Suppose the partition always puts 10%10\% of the keys on one side and 90%90\% on the other: T(n)=T(n/10)+T(9n/10)+nT(n) = T(n/10) + T(9n/10) + n. The shallowest path has depth log⁡10n\log_{10} n, the deepest log⁡10/9n≈21.9log⁡10n\log_{10/9} n \approx 21.9 \log_{10} n, and each level costs at most nn; the total is between nlog⁡10nn \log_{10} n and nlog⁡10/9nn \log_{10/9} n, so Θ(nlog⁡n)\Theta(n \log n). The constant is larger than for balanced splits but the order is the same. By contrast a split of one key against the rest is Θ(n2)\Theta(n^2).

EX 4The probability argument for two keys

Medium

Take four keys and call them z1<z2<z3<z4z_1 < z_2 < z_3 < z_4 in sorted order. Consider z1z_1 and z3z_3. They are compared only if the first pivot among z1,z2,z3z_1, z_2, z_3 is z1z_1 or z3z_3: probability 2/32/3. If z2z_2 is chosen first, z1z_1 and z3z_3 go to different sides and are never compared. For adjacent keys zi,zi+1z_i, z_{i+1} the probability is 2/2=12/2 = 1: they are always compared (nothing can separate them). For z1z_1 and znz_n it is 2/n2/n, which is why the extremes are rarely compared.

EX 5Recurrences and space

GATE level

(a) Quicksort always picks the median as pivot (found for free): T(n)=2T(n/2)+n=Θ(nlog⁡n)T(n) = 2T(n/2) + n = \Theta(n \log n). (b) Always the smallest: T(n)=T(n−1)+n=Θ(n2)T(n) = T(n - 1) + n = \Theta(n^2). (c) A partition that splits into n/4n/4 and 3n/43n/4: Θ(nlog⁡n)\Theta(n \log n). (d) The recursion depth and stack in the worst case: n−1n - 1 frames, Θ(n)\Theta(n) space; with the smaller part first, at most ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1 frames. (e) Which input is worst for quicksort with the last element as pivot? Sorted or reverse-sorted input (and all-equal input for the Lomuto partition above). (f) Is quicksort stable? No: for 2a,2b,12_a, 2_b, 1 the partition swaps 11 with 2a2_a and gives 1,2b,2a1, 2_b, 2_a.

Cheat box

Cheat box

  • Partition: pivot to its final place, ≤\le left, >> right; n−1n - 1 comparisons (Lomuto, last pivot).
  • T(n)=T(k)+T(n−1−k)+Θ(n)T(n) = T(k) + T(n - 1 - k) + \Theta(n). Worst: T(n−1)+n=Θ(n2)T(n - 1) + n = \Theta(n^2), n(n−1)/2n(n-1)/2 comparisons (sorted, reversed, and all-equal for Lomuto). Best/balanced: Θ(nlog⁡n)\Theta(n \log n).
  • Average (random order or random pivot): 2(n+1)Hn−4n≈1.39nlog⁡2n=Θ(nlog⁡n)2(n + 1)H_n - 4n \approx 1.39 n \log_2 n = \Theta(n \log n).
  • Any split with both sides a constant fraction of nn is Θ(nlog⁡n)\Theta(n \log n).
  • In place, not stable, not adaptive. Space: O(log⁡n)O(\log n) average stack, O(n)O(n) worst; smaller-part-first gives ≤⌊log⁡2n⌋+1\le \lfloor \log_2 n \rfloor + 1.
  • Pivot rules: random, median of three, median of medians (worst case nlog⁡nn \log n).
  • Equal keys: Lomuto with ≤\le degrades to n2n^2; Hoare and three-way partition are fine.

Traps and GATE patterns

Connections

Quicksort is an instance of divide and conquer with all the work in the divide step; its recurrence is solved with the methods of solving recurrences. Compare it with merge sort and heap sort in stability and comparison of sorts. Its partition also finds the kk-th smallest key in expected linear time (quickselect, divide and conquer applications).

PYQs

7 previous year questions from your book. I re-solved each one myself (4 by running or simulating, 3 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2020 · NAT · 1 markQ4 · page 108 of the book
An array of 25 distinct elements is to be sorted
using quicksort. Assume that the pivot element is
chosen uniformly at random. The probability that
the pivot element gets placed in the worst possible
location in the first round of partitioning (rounded
off to 2 decimal places) is
GATE 2016 · Set 1 · MCQQ8 · page 109 of the book
The worst-case running time of Insertion sort,
Merge sort and Quick sort, respectively, are:
  • (a)θ(nlogn), θ(nlogn) and θ(n2)
  • (b)θ(n2) , θ(n2) and θ(nlogn)
  • (c)θ(n2), θ(nlogn) and θ(nlogn)
  • (d)θ(n2), θ(nlogn) and θ(n2)
GATE 2015 · Set 2 · MCQ · 1 markQ9 · page 109 of the book
Suppose you are provided with the following
function declaration in the C programming
language.
int partition(int a[ ], int n);
The function treats the first element of a[] as a
pivot, and rearranges the array so that all elements
less than or equal to the pivot is in the left part of
the array, and all elements greater than the pivot
is in the right part. In addition, it moves the pivot
so that the pivot is the last element of the left part.
The return value is the number of elements in the
left part. The following partially given function in
the C programming language is used to find the
k-th smallest element in an array a[ ] of size n
using the partition function. We assume k <= n
C
int kth_smallest(int a[], int n, int k)
{
int left_end = partition(a, n);
if ( left_end+1 == k ){
return a[left_end];
}
if ( left_end+1 > k ){
return kth_smallest(
);
} else {
return kth_smallest(
);
}
}
The missing arguments lists are respectively
  • (a)(a, left_end, k) and (a + left_end +1, n- left_end -1, k-left_end -1)
  • (b)( a, left_end, k ) and ( a, n-left_end -1, k- left_end -1 )
  • (c)( a + left_end +1, n-left_end -1, k- left_end -1 ) and ( a, left_end, k )
  • (d)(a, n-left_end -1, k-left_end -1) and (a, left_end, k)
year not read yetQ10 · page 109 of the book
Which one of the following is the recurrence
equation for the worst case time complexity of the
Quicksort algorithm for sorting n ( >=2) numbers?
In the recurrence equations given in the options
below, c is a constant.
  • (a)T(n)=2T(n/2)+cn
  • (b)T(n)=T(n-1)+T(1)+cn
  • (c)T(n)=2T(n-1)+cn
  • (d)T(n)=T(n/2)+cn
GATE 2014 · Set 3 · MCQ · 2 marksQ11 · page 109 of the book
You have an array of n elements. Suppose you
implement quick sort by always choosing the
central element of the array as the pivot. Then the
tightest upper bound for the worst case
performance is
  • (a)O(n2)
  • (b)O(nlogn)
  • (c)θ(nlogn)
  • (d)O(n3)
GATE 2014 · Set 1 · MCQ · 2 marksQ12 · page 109 of the book
Let P is a quick sort program to sort numbers in
ascending order using the first element as the pivot.
Let t1 and t2 be the number of comparisons made by
P for the inputs [1 2 3 4 5] and [4 1 5 3 2] respectively.
Which one of the following holds?
  • (a)t1 = 5
  • (b)t1 < t2
  • (c)t1 > t2
  • (d)t1 = t2
GATE 2009 · MCQ · 1 markQ15 · page 110 of the book
In quick sort, for sorting n elements, the (n/4)th
smallest element is selected as pivot using an
O(n) time algorithm. What is the worst case time
complexity of the quick sort?
  • (a)θ(n)
  • (b)θ(nlogn)
  • (c)θ(n2)
  • (d)θ(n2logn)

Self-check

Question 1

How many comparisons does quicksort (last element as pivot) make on an array of nn equal keys with the Lomuto partition shown here?

Show answer

n(n−1)/2n(n-1)/2: every key is ≤\le the pivot, so each partition leaves an empty right part and a left part one key shorter.

Question 2

Why is the average case of quicksort Θ(nlog⁡n)\Theta(n \log n) although a single partition can be very unbalanced?

Show answer

On average the splits are balanced enough: two keys are compared with probability 2/(j−i+1)2/(j - i + 1) and summing gives 2(n+1)Hn−4n≈1.39 nlog⁡2n2(n+1)H_n - 4n \approx 1.39\, n \log_2 n; also any proportional split gives nlog⁡nn \log n.

Question 3

How can the stack depth of quicksort be limited to O(log⁡n)O(\log n) in the worst case?

Show answer

Recurse on the smaller part only and handle the larger part with a loop: each recursive call is on at most half the keys.

Question 4

Is quicksort stable?

Show answer

No: the partition swaps keys across the pivot, which can move a key past an equal key.

Revision card

One-screen revision

  • Partition then recurse; T(n)=T(k)+T(n−1−k)+nT(n) = T(k) + T(n - 1 - k) + n.
  • Worst n(n−1)/2n(n-1)/2 (Θ(n2)\Theta(n^2)): sorted, reversed, all-equal (Lomuto). Best and average Θ(nlog⁡n)\Theta(n \log n); average =2(n+1)Hn−4n≈1.39nlg⁡n= 2(n+1)H_n - 4n \approx 1.39 n \lg n.
  • Proportional splits are Θ(nlog⁡n)\Theta(n \log n); random pivot gives expected bound on every input.
  • In place, unstable; stack O(log⁡n)O(\log n) average, O(n)O(n) worst, ≤lg⁡n+1\le \lg n + 1 with smaller-part-first.
  • Three-way partition handles duplicates.

References

  • ·Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms (3rd edition), Chapter 7 Quicksort
  • ·Sedgewick and Wayne, Algorithms (4th edition), Section 2.3 Quicksort
  • ·Knuth, The Art of Computer Programming, Volume 3, Section 5.2.2 Sorting by exchanging

Verification

Quicksort with the Lomuto partition and the last element as pivot was re-implemented in Python and run on EVERY permutation of up to 9 keys: the average number of comparisons equals 2(n+1)H_n - 4n exactly (Fractions), the worst case equals n(n-1)/2, the partition invariants hold after every partition, the recursion depth on sorted input is n - 1, and the smaller-part-first version never needed a depth above floor(lg n) + 1. The expected-value recurrence C(n) = n - 1 + (2/n) sum C(k) was solved exactly for n up to 39 and the pair-probability argument (two keys are compared with probability 2/(j - i + 1)) reproduces the same sum algebraically. The C program on this page produced the table (random column: 400 random orders, within 4 percent of the exact expectation) and the animation is a real run of the shown code. Hoare partition, median-of-three and the three-way partition are described from the standard texts and were not separately measured. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (loop counts, recurrences, merge and quicksort counts and averages, hash probes and load-factor formulas, DP tables, MST and shortest-path runs, Floyd matrices); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; The definition of partition said the pivot is in its final place for every partition scheme; it now says this holds for the Lomuto partition and that Hoare's original partition returns a split point. Status raised to self-checked; verified needs a textbook or human check.

last verified: never

My notes (saved in this browser)