ProgrammingVery hard
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?
- A. C, B, A
- B. C, A, B
- C. A, B, C
- D. B, A, C
Correct answer: A. C, B, A
The first swap moves C to the front and sends A to the end position of the pass, so B and A end up reversed. Selection sort with swaps is not stable.
More C Programming questions
- 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?
- struct S { int id; int v; }; struct S a[4] = {{1,9},{2,8},{3,7},{4,6}}; struct S b[4]; memcpy(b, a, sizeof a); b[0].v = 0; printf("%d %d"…