Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

Selection sort (ascending, swap the minimum of the unsorted suffix into place each pass, skipping the swap if it is already in place) is run on [77, 46, 59, 51, 74, 96, 55, 51]. How many swaps happen in total?

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

Correct answer: D. 6

A swap happens only in passes where the found minimum is not already at the current position: 6 swaps here (at most n-1 = 7).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic