ProgrammingVery hard
Insertion sort (shift larger elements right, then place the key) is applied to {4, 1, 3, 2}. How many element shifts happen in total?
- A. 3
- B. 5
- C. 4
- D. 6
Correct answer: C. 4
Each shift removes one inversion, and the input has 4 inversions: (4,1), (4,3), (4,2) and (3,2).
More C Programming questions
- The third smallest value of the keys {40, 10, 30, 20, 50} is which value?
- How many inversions does the array {2, 4, 1, 3, 5} contain?
- Records (A, 3, x), (B, 3, a), (C, 1, m) are sorted by score descending and then by the name field ascending. What is the order of the…
- A struct P ps[] holds records, and an array of pointers pp[] is sorted with qsort. What happens to the records in ps?
- Which argument is correct as the size parameter in qsort for an array struct P recs[] of n records?
- A comparator for qsort is written as int cmp(const void a, const void b) { return ((const struct P )a)->k > ((const struct P )b)->k; }…