ProgrammingHard
Binary search with lo = 0, hi = n - 1 on n = 1000 sorted records, looking for a key not in the array, performs how many probes at most?
- A. 9
- B. 10
- C. 11
- D. 1000
Correct answer: B. 10
Each probe halves the range, and 2^10 = 1024 >= 1000, so at most 10 probes are needed. Nine probes cover only 512 positions.
More C Programming questions
- Insertion sort is applied to a = {5, 2, 4, 6, 1, 3} and each element moved one slot to the right while shifting counts as one move. How…
- A selection sort swaps the minimum into place, but only when the minimum is not already in place. How many swaps does it make on {7, 2, 9…
- Records are counted into buckets by key 0 to 2 in a stable counting sort. Input: Ann 2, Bob 0, Cy 2, Dee 1, Eve 0. What is the output…
- Keys {4, 7, 2, 9, 6, 1} are split into the even keys first and then the odd keys, keeping each group in input order. What is the result?
- Records (P,5), (Q,9), (R,9), (S,3) are scanned with if (s.score >= best.score) best = s; starting from the first record. Which name is kept?
- Records (Raj,30), (Ana,25), (Raj,22), (Ana,40) are sorted first by age with a stable sort, then by name with another stable sort. What is…