ProgrammingVery hard

A selection sort swaps the minimum into place, but only when the minimum is not already in place. How many swaps does it make on {7, 2, 9, 4, 1, 8}?

  1. A. 3
  2. B. 5
  3. C. 6
  4. D. 4

Correct answer: D. 4

Each pass finds the minimum of the unsorted part. A swap is needed only when that minimum is not at the front. Tracing the passes gives the count shown.

More C Programming questions

Exams that ask this topic