GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A sorted array was rotated: [15, 18, 22, 25, 30, 2, 4, 7, 9, 11, 12, 14]. The standard rotated binary search (compare a[lo] <= a[mid] to find the sorted half, then decide the half) is run for the keys 22, 9, 14 and 3. What are the total number of loop iterations over the four searches, and the result for key 3?

  1. A. 10 iterations, not found
  2. B. 12 iterations, index 5
  3. C. 15 iterations, not found
  4. D. 12 iterations, not found

Correct answer: D. 12 iterations, not found

Iterations per key are [2, 2, 4, 4]; key 3 is absent (it lies between 2 and 4 in the second sorted run) and returns -1.

More Programming and Data Structures (GATE) questions

Exams that ask this topic