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 19, 42, 33, 11, 25, 48, and its first pick is the 33. What is the row just after the 33 is placed?

194233112548
the answer, and why

the answer is D

The 33 swaps to the end: 19, 42, 48, 11, 25, 33. The 19 is smaller and stays. The 11 swaps with the 42: 19, 11, 48, 42, 25, 33. The 25 swaps with the 48: 19, 11, 25, 42, 48, 33. Then the 33 swaps with the 42 just after them.

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 numbers

question 2

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

666666
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 numbers