Data Structures & AlgorithmsVery hardGATE CS · DSA
Array [61, 75, 77, 8, 27, 29, 31, 32, 47, 56] is a sorted array rotated at pivot 7. Using the standard O(log n) rotated-array binary search (decide which half is sorted, then check if the target lies in it), at what index is 77 found?
- A. 3
- B. 7
- C. 1
- D. 2
Correct answer: D. 2
At each step one half (low..mid or mid..high) is guaranteed sorted; checking whether the target falls in that sorted half's range decides which half to keep. Tracing this on the array places 77 at index 2.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Elevation map [2, 2, 5, 0, 2, 0, 3, 1, 1, 1] (bar width 1). Using the two-pointer / prefix-max approach for trapping rain water, how much…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "BAAAABBAACB" are anagrams of "AB"?
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- Floyd's cycle detection runs on a linked list 1 → 2 → ... → 8 whose last node's next pointer points back to node 4 (0-based position 3)…