Skip to content

Randomised quick sort

ordering

Level 3 of 3

Also called Randomised quicksort.

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 randomised quick sort's own run on the numbers shown.

choose one

question 1

Randomised quick sort works on 48, 41, 20, 44, 13, 34, and its first pick is the 41. What is the row just after the 41 is placed?

484120441334
the answer, and why

the answer is B

The 41 swaps to the end: 48, 34, 20, 44, 13, 41. Each smaller number joins the small side at the front, then the 41 swaps in just after them: 34, 20, 13, 41, 48, 44.

if you chose another

  • That sorts both sides too, which waits for later splits.
  • That stops before the pivot swaps into place.
  • That is the row just after the pivot moves to the end.

new numbersthe test page's numbers

question 2

How many comparisons does randomised quick sort make on 95, 95, 95, 95, 95, 95, whatever its picks?

959595959595
the answer, and why

the answer is D

No number is smaller than its pivot, so the parts hold 6, 5, 4, 3, 2 numbers. That is 5 + 4 + 3 + 2 + 1 = 15.

if you chose another

  • That is the first split alone.
  • That counts each part of m numbers as m comparisons, the pivot with itself too, down to the last lone number.
  • That is one comparison for each number.

new numbersthe test page's numbers