Data Structures & AlgorithmsModerateGATE CSE
What is the maximum number of element comparisons a binary search (one three-way comparison per step) makes on a sorted array of 100 elements?
- A. 7
- B. 6
- C. 8
- D. 10
Correct answer: A. 7
Each step halves the range: floor(log2 100) + 1 = 7 probes in the worst case.
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 sorted array [1, 1, 2, 2, 2, 3, 5, 5, 8] is de-duplicated in place by two pointers: a write index w starts at 1 and each element a[i]…
- The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated left by 3 positions using three reversals: reverse the first 3 elements, reverse the…
- Keys 12, 22, 32, 13, 23 are inserted in this order into an empty hash table of size 10 using h(k) = k mod 10 and linear probing. At which…
- A queue is built from two stacks: enqueue pushes on stack IN; dequeue pops from OUT, first moving all of IN onto OUT (one pop and one push…
- What is the minimum number of adjacent swaps needed to sort [3, 1, 2, 5, 4] in ascending order?
- For each element of [4, 5, 2, 25, 7, 8], take the first strictly greater element to its right (or -1 if there is none). What is the sum of…