Data Structures & AlgorithmsHard
Why is the standard binary-search probe count for an unsuccessful search about log₂(n), not n?
- A. Every element is probed once.
- B. Each probe halves the remaining range, so after about log₂ n probes the range is empty.
- C. The search always scans the array left to right.
- D. Binary search doubles the range each probe.
Correct answer: B. Each probe halves the remaining range, so after about log₂ n probes the range is empty.
Each comparison discards half of the live range, so the range shrinks to nothing in about log₂ n steps, whether or not the key is present.
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
- When sorting records by key with counting sort, why must the placement pass proceed in a specific direction for stability?
- Why does the cycle-based 'place each value at its index' method find missing numbers in linear time?
- Why does Floyd's method for finding a duplicate in an array of n+1 values in 1..n view the array as a linked structure?
- Stable sorting by two keys works by sorting twice. Which order of passes gives the lexicographic order with the first key as primary?
- Why does the median of two sorted arrays of sizes m and n not require merging both arrays fully?
- Which property makes the number of inversions of a rotated sorted array equal to a simple product?