All subjects · Mathematics · WDM11 (D1)

Quick sort

Quick sort splits a list around a pivot, then repeats on each smaller list. Edexcel fixes how the pivot is chosen, so everyone gets the same working.

Choosing the pivot

The pivot is the middle item of each sub-list. For a list of N items it is in position (N + 1)/2 when N is odd and (N + 2)/2 when N is even (the right-hand of the two middle items). So for 7 items use the 4th; for 8 items use the 5th.

One pass

Write the items smaller than the pivot in the order they appear, then the pivot, then the larger items in the order they appear. Box or underline the pivot: it is now in its final place.

Repeating

In the next pass choose a pivot from every sub-list of two or more items at the same time. A sub-list of one item is already in place. Continue until every item has been a pivot or sits alone. Check no numbers have been lost or copied twice.

Descending order

For descending order write the items larger than the pivot first, then the pivot, then the smaller items.

Worked example

Use quick sort to put 21, 47, 12, 35, 8, 30, 16 into ascending order.

  1. Pass 1: pivot 35 gives 21, 12, 8, 30, 16, 35, 47
  2. Pass 2: pivot 8 gives 8, 21, 12, 30, 16, 35, 47
  3. Pass 3: pivot 30 gives 8, 21, 12, 16, 30, 35, 47
  4. Pass 4: pivot 12 gives 8, 12, 21, 16, 30, 35, 47
  5. Pass 5: pivot 16 gives 8, 12, 16, 21, 30, 35, 47

Answer: Sorted: 8, 12, 16, 21, 30, 35, 47

Key idea: Pivot = middle item ((N + 1)/2 or (N + 2)/2); smaller items before, larger after, original order kept; pivot every sub-list each pass.

Check yourself

  1. A list has 12 items. In which position is the first quick sort pivot?
    Show answer

    7. N = 12 is even, so the pivot is in position (12 + 2)/2 = 7.

  2. What is the first pivot when quick sort is applied to 52, 18, 64, 33, 27, 71, 45, 39?
    Show answer

    27. There are 8 items, so the pivot is the 5th item, 27.

  3. What is the list 52, 18, 64, 33, 27, 71, 45, 39 after the first pass of an ascending quick sort?
    • 18, 27, 33, 39, 45, 52, 64, 71
    • 18, 27, 52, 64, 33, 71, 45, 39
    • 18, 33, 27, 39, 45, 52, 64, 71
    • 52, 18, 64, 33, 27, 71, 45, 39
    Show answer

    18, 27, 52, 64, 33, 71, 45, 39. Pivot 27: smaller items in order, then 27, then larger items in order: 18, 27, 52, 64, 33, 71, 45, 39.

  4. After pass 1 of an ascending quick sort, 21, 47, 12, 35, 8, 30, 16 becomes 21, 12, 8, 30, 16, 35, 47 with pivot 35. Which pivot is used for the left sub-list in pass 2?
    • 12
    • 30
    • 8
    • 21
    Show answer

    8. The left sub-list 21, 12, 8, 30, 16 has 5 items, so its pivot is the 3rd item, 8.

  5. How many passes, each choosing at least one pivot, does quick sort need to sort 52, 18, 64, 33, 27, 71, 45, 39?
    Show answer

    5. Passes: pivot 27; pivot 71; pivot 33; pivot 45; pivot 64.

  6. A quick sort into descending order is applied to 15, 42, 8, 27, 33, 19. What is the list after pass 1?
    • 15, 8, 19, 27, 42, 33
    • 42, 27, 33, 15, 8, 19
    • 42, 33, 27, 15, 8, 19
    • 42, 33, 27, 19, 15, 8
    Show answer

    42, 33, 27, 15, 8, 19. 6 items: the pivot is the 4th item, 27. Larger items first in order (42, 33), then 27, then smaller (15, 8, 19): 42, 33, 27, 15, 8, 19.

  7. In a quick sort pass, how are the items smaller than the pivot written?
    • In the same order as they appear in the list
    • In ascending order
    • In descending order
    • In any order
    Show answer

    In the same order as they appear in the list. Items keep their relative order; only the pivot is placed. This makes the working checkable.

Practise with instant feedback

Sources

Last updated 7 November 2026. Spotted a mistake? Tell us.