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)?
- A. (Ana,40), (Ana,25), (Raj,30), (Raj,22)
- B. (Ana,25), (Raj,22), (Ana,40), (Raj,30)
- C. (Raj,22), (Raj,30), (Ana,25), (Ana,40)
- 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
- A swap-based selection sort is run on the records (A,2), (B,2), (C,1) using the key only. What is the final order?
- Upper bound: in the sorted keys 1, 3, 5, 5, 5, 8, 9 (0-based), what index does bisectright / upperbound return for x = 5?
- To find the k-th largest of 10^6 records by score, which approach is correct and fast enough?
- To find duplicate keys among 2 x 10^5 records, which method is correct and fast enough?
- A qsort comparator must sort records by name in descending order using strcmp on char name[16] fields. Which is correct?
- An array of 10^6 records of 100 bytes each must be sorted. Which approach is correct and fast enough?