ProgrammingHard
Which sort is stable and runs in O(n log n) worst case, suitable for struct arrays that must keep equal-key order?
- A. Quicksort as usually written
- B. Heapsort
- C. Selection sort
- D. Merge sort
Correct answer: D. Merge sort
Merge sort is stable and O(n log n) in the worst case. Typical quicksort and heapsort are not stable, and selection sort is quadratic.
More C Programming questions
- 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?
- int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (r)[3] = m + 1; What is r[0][2]?
- In an n x n row-major int matrix with n = 5, what is the flat index of the diagonal cell (i, i) for i = 2?