Skip to content

Quickselect

finding

Level 3 of 3

Also called Hoare's selection algorithm.

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

choose one

question 1

Quickselect looks for place 1 in 86, 27, 56, 63, 51, 64. What is the row just after its first pivot is placed?

862756635164
the answer, and why

the answer is D

The pivot is the last number, 64. Each smaller number joins the small side at the front, then the 64 swaps in just after them, to place 5: 27, 56, 63, 51, 64, 86.

if you chose another

  • That is the whole row in order. Quickselect never sorts it.
  • 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 quickselect make asking 90, 81, 77, 53, 52, 47, 15 for place 4?

90817753524715
the answer, and why

the answer is D

Each pivot is the smallest or the biggest left, in turn, so each part is one shorter. 6 + 5 + 4 + 3 + 2 + 1 = 21.

if you chose another

  • That is asking for place 7, where the second pivot, 90, is found.
  • That is the first split alone. The search keeps splitting.
  • That counts the pivot as compared with itself, once in each of the six splits, 7 + 6 + 5 + 4 + 3 + 2.

new numbersthe test page's numbers

question 3

Which search costs quickselect the fewest comparisons? Each option is a row and the place asked for, as the lead writes them.

the answer, and why

the answer is B

Quickselect makes 5 comparisons for 89, 96, 20, 92, 64, 74; 3, the fewest of the four.

if you chose another

  • Quickselect makes 6 comparisons for this one, more than 5.
  • Quickselect makes 8 comparisons for this one, more than 5.
  • Quickselect makes 8 comparisons for this one, more than 5.

new numbersthe test page's numbers