Data Structures & AlgorithmsModerateGATE CS · DSA
Binary search with mid = (lo + hi) // 2 (lo = 0, hi = n − 1, loop while lo ≤ hi) looks for 81 in [22, 26, 29, 31, 36, 38, 46, 51, 70, 81, 93, 94, 99]. Which elements are compared with the key, in order?
- A. 46
- B. 46, 81, 93
- C. 46, 81
- D. 46, 93, 70, 81
Correct answer: C. 46, 81
Each probe halves the range: 46 → 81. 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
- The intervals [15, 16], [11, 16], [4, 9], [4, 8], [8, 12], [20, 22] are sorted by start and merged (intervals that touch, like [2, 4] and…
- For s = "cbbbccadbcdacd", what is the length of the longest substring with at most 2 distinct characters, and how many substrings (by…
- Keys 81, 25, 26, 79, 49, 55, 59, 93 are inserted in this order into an empty table of size 11 with h(k) = k mod 11 and linear probing…
- Only the lower triangle (including the diagonal) of a 10 × 10 matrix is stored COLUMN by column in a 1-D array B starting at B[0] (indices…
- A min-stack keeps a second stack of running minimums. What is printed? python st, mn, out = [], [], [] for op in [8, "pop", 8, 8, "pop"…
- Reverse a singly linked list in groups of k (a final group shorter than k is left as it is). What is printed? python def revk(h, k): cnt…