ProgrammingVery hard

A struct array of n records is sorted by key. The code stores a record index inside each record before sorting, so that it can recover the original order. Which problem does this solve?

  1. A. It makes qsort run in O(n) time
  2. B. It removes the need for a comparator
  3. C. It makes bsearch work on unsorted data
  4. D. It makes the sort effectively stable, because equal keys are ordered by their original index

Correct answer: D. It makes the sort effectively stable, because equal keys are ordered by their original index

Adding the original index as a tiebreaker gives a total order, so the result is the same as a stable sort on the key.

More C Programming questions

Exams that ask this topic