Data Structures & AlgorithmsHardGATE CS · Product placement
Binary search with mid = (lo + hi) // 2 (lo = 0, hi = n − 1, loop while lo ≤ hi) looks for 86 in [11, 13, 17, 24, 25, 32, 36, 58, 65, 86, 90]. Which elements are compared with the key, in order?
- A. 32, 65, 86
- B. 32, 65, 90, 86
- C. 32, 65, 86, 90
- D. 32, 65
Correct answer: A. 32, 65, 86
Each probe halves the range: 32 → 65 → 86. The key is found at index 9.
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
- Rabin–Karp with a good rolling hash is used to find a pattern of length m in a text of length n. Which statement is correct?
- Reverse the order of words, collapsing multiple spaces. What is printed? python s = " the is new code " w = s.split() print("|" + "…
- Rabin–Karp with base 10 and a deliberately small modulus counts true matches and spurious hits (hash equal, text different). What is…
- 11 people stand in a circle numbered 1 to 11. Counting starts at person 1, and every 4th person is removed (counting continues from the…
- Kadane's algorithm runs on [−4, −7, 9, 3, −5, 4, 1, 4, 8]. What is the maximum sum of a non-empty contiguous subarray?
- How many contiguous subarrays of [3, 2, −3, 5, 2, −1, 0, 1, 2] have sum exactly 3? (Prefix sums with a hash map of prefix-sum frequencies.)