ProgrammingHard
A recursive binary search on n = 1000 sorted values reaches what maximum recursion depth?
- A. 9
- B. 11
- C. 10
- D. 1000
Correct answer: C. 10
Each call halves the range, so the depth is about log2(1000), which rounds up to 10.
More C Programming questions
- Merge sort on n = 2^20 elements has what recursion depth?
- An algorithm does O(n) work on each of the n levels of a recursion that removes one element per level. Which total is correct?
- A loop calls strlen(s) on a fixed string of length 10^4 once per character of the same string. How many characters are read in total?
- A function computes the sum of 1 to n by recursion with depth n. For n = 10^6, what is the main risk?
- A program increments a counter inside three nested loops, each running n = 100 times. How many increments occur?
- In a loop for (i = 0; i < n; i++) x = x 2 % m; with m = 1000000007 and x kept as long long, what is the cost?