Data Structures & AlgorithmsModerateGATE CS · DSA

Quickselect returns the k-th smallest element of an unsorted array in expected O(n) time. For [29, 18, 10, 32, 39, 19, 36, 13] and k = 4, what does it return, and how many elements does the first Lomuto partition (pivot = last element) place to the LEFT of the pivot?

  1. A. 19; 6
  2. B. 19; 1
  3. C. 29; 1
  4. D. 18; 1

Correct answer: B. 19; 1

The k-th smallest of [10, 13, 18, 19, 29, 32, 36, 39] is 19. The first partition around 13 puts the 1 smaller elements to its left; quickselect then recurses into only one side.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic