Data Structures & AlgorithmsHardGATE CS · Product placement

Selection sort (ascending; in pass i find the minimum of the unsorted part and swap it into position i only if it is not already there) is applied to [44, 58, 13, 30, 19, 25, 17, 11]. What is the array after 3 passes, and how many swaps will the complete sort make?

  1. A. [11, 13, 17, 30, 19, 25, 58, 44]; 7 swaps in total
  2. B. [13, 30, 44, 58, 19, 25, 17, 11]; 6 swaps in total
  3. C. [13, 19, 25, 17, 11, 30, 44, 58]; 6 swaps in total
  4. D. [11, 13, 17, 30, 19, 25, 58, 44]; 6 swaps in total

Correct answer: D. [11, 13, 17, 30, 19, 25, 58, 44]; 6 swaps in total

After 3 passes the 3 smallest values sit in front: [11, 13, 17, 30, 19, 25, 58, 44]. Over the whole sort, 6 passes find their minimum elsewhere and swap, so 6 swaps (at most n − 1).

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

Exams that ask this topic