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?
- A. 10 iterations, not found
- B. 12 iterations, index 5
- C. 15 iterations, not found
- 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.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Two singly linked lists merge into a common tail: list X has 7 nodes before the merge point, list Y has 11 nodes before it, and the shared…
- A singly linked list 1 -> 2 -> ... -> 12 is modified by reversing the sublist from position 3 to position 9 (1-indexed, inclusive), and…
- Eight sorted lists of 100 keys each (800 distinct keys) are merged with the standard two-way merge, whose worst case for lists of sizes p…
- The number of nodes of a complete binary tree is found recursively: compute the leftmost-path height and the rightmost-path height of the…
- A BST is built from the sorted array 1, 2, ..., 14 by recursion: the root is a[mid] with mid = (lo + hi) / 2 (integer division), then the…
- In a binary tree given as (key, left, right) = (10, (-20, (8), (-6, (4), -)), (15, (-3), (12, (7), (-9)))), a 'path' is any sequence of…