ProgrammingHard

A selection sort on 5 elements (find the minimum, swap into place) makes how many key comparisons in total, for any input?

  1. A. 4
  2. B. 5
  3. C. 10
  4. D. 7

Correct answer: C. 10

Selection sort always compares every remaining element in each pass, so the comparison count is n(n-1)/2 = 10 regardless of the data.

More C Programming questions

Exams that ask this topic