ProgrammingModerate
Merge sort on n = 2^20 elements has what recursion depth?
- A. 19
- B. 21
- C. 1048576
- D. 20
Correct answer: D. 20
Each level halves the subarray, so the depth is log2(2^20) = 20.
More C Programming questions
- 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?
- Which loop computes the number of trailing zeros of n in O(number of zeros) time for an unsigned n greater than zero?