Skip to content

Quick sort

ordering

Level 2 of 3

Also called Partition-exchange sort.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from quick sort's own run on the numbers shown.

choose one

question 1

Quick sort starts on 44, 30, 48, 25, 15, 28. What is the row just after its first pivot is placed?

443048251528
the answer, and why

the answer is C

The pivot is the last number, 28. Each smaller number joins the small side at the front, then the 28 swaps in just after them: 25, 15, 28, 44, 30, 48.

if you chose another

  • That sorts the right part too, which waits for later splits.
  • That stops before the pivot swaps into place.
  • That is the row before the split.

new numbersthe test page's numbers

question 2

How many comparisons does quick sort make on 10, 15, 17, 24, 26, 27, 30?

10151724262730
the answer, and why

the answer is B

Each pivot is the biggest left, so the parts hold 7, 6, 5, 4, 3, 2 numbers. That is 6 + 5 + 4 + 3 + 2 + 1 = 21.

if you chose another

  • That is the first split alone. Quick sort keeps splitting.
  • That is the cheapest row of 7.
  • That counts 7 comparisons for the first split, but the pivot is not compared with itself.

new numbersthe test page's numbers

question 3

Which row costs quick sort the fewest comparisons?

the answer, and why

the answer is C

Quick sort makes 14 comparisons on 1, 2, 11, 15, 7, 14, 20, 8, the fewest of the four.

if you chose another

  • Quick sort makes 17 comparisons on this row, more than 14.
  • Quick sort makes 20 comparisons on this row, more than 14.
  • Quick sort makes 16 comparisons on this row, more than 14.

new numbersthe test page's numbers