ProgrammingVery hard

Records (Raj,30), (Ana,25), (Raj,22), (Ana,40) are sorted first by age with a stable sort, then by name with another stable sort. What is the final order of (name, age)?

  1. A. (Ana,40), (Ana,25), (Raj,30), (Raj,22)
  2. B. (Ana,25), (Raj,22), (Ana,40), (Raj,30)
  3. C. (Raj,22), (Raj,30), (Ana,25), (Ana,40)
  4. D. (Ana,25), (Ana,40), (Raj,22), (Raj,30)

Correct answer: D. (Ana,25), (Ana,40), (Raj,22), (Raj,30)

Stability means the age order from the first pass survives inside each name group. The final sort by name therefore leaves Ana 25 before Ana 40 and Raj 22 before Raj 30.

More C Programming questions

Exams that ask this topic