ProgrammingModerate

An array of 10^6 records of 100 bytes each must be sorted. Which approach is correct and fast enough?

  1. A. Bubble sort on the records themselves, about 10^12 comparisons
  2. B. qsort on an array of pointers to the records, about 2 x 10^7 comparisons
  3. C. Insertion sort on the records, about 10^12 comparisons
  4. D. Selection sort on the records, about 10^12 comparisons

Correct answer: B. qsort on an array of pointers to the records, about 2 x 10^7 comparisons

Sorting pointers keeps swaps cheap, and n log n comparisons for n = 10^6 is about 2 x 10^7. The quadratic sorts make about 10^12 comparisons.

More C Programming questions

Exams that ask this topic