ProgrammingModerate
A recursive merge sort on 10^6 elements makes how many comparisons, roughly?
- A. About 10^6, which is n
- B. About 10^12, which is n^2
- C. About 2 x 10^7, which is n log2 n
- D. About 10^9, which is n^1.5
Correct answer: C. About 2 x 10^7, which is n log2 n
Merge sort does about n log2 n comparisons, and log2(10^6) is about 20, so about 2 x 10^7.
More C Programming questions
- Which function call costs O(n) time per call and can be avoided by caching its result in a loop?
- A recurrence T(n) = 2 T(n/2) + n describes which algorithm, with which complexity?
- For a number n up to 10^18 read as a decimal string, what is the number of digits, computed with one pass?
- A program keeps a set of at most 10^5 ints and answers membership queries 10^5 times. Which structure is correct and fast enough?
- Which statement about finding the length of a null-terminated C string is correct?
- Which code gives the correct sum of the first n squares, for n up to 10^6, using a closed form in O(1)?