ProgrammingHard
Sorting 2 x 10^6 structs with qsort in C takes about how many comparisons?
- A. About 2 x 10^6
- B. About 4 x 10^7
- C. About 4 x 10^12
- D. About 2 x 10^9
Correct answer: B. About 4 x 10^7
n log2 n with n = 2 x 10^6 is about 2 x 10^6 x 21 = 4.2 x 10^7 comparisons, well within a typical limit.
More C Programming questions
- A list of records must be kept sorted while new records arrive one at a time. Which structure gives the best total cost for 10^5 inserts…
- Which sort is stable and runs in O(n log n) worst case, suitable for struct arrays that must keep equal-key order?
- How many records remain after a struct array of 7 records is filtered to drop those with a key equal to the previous key, when the array…
- Rotating the 2 x 2 matrix [[1, 2], [3, 4]] by 90 degrees counter-clockwise gives which first row?
- The matrix int a[3][3] = {[1][1] = 5}; is zero-initialised everywhere else (C99 designators). What is a[0][0] + a[1][1] + a[2][2]?
- For the array int a[2][3] = {{1, 2, 3}, {4, 5, 6}}, what does ((a + 1) + 2) print?