Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

Selection sort (find the minimum of the unsorted part, swap it to the front only if it is not already there) sorts [29, 10, 14, 37, 13] into ascending order. How many swaps does it make?

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

Correct answer: B. 3

Pass 1: min 10 swaps with 29 → [10, 29, 14, 37, 13]. Pass 2: min 13 swaps with 29 → [10, 13, 14, 37, 29]. Pass 3: 14 is already in place (no swap). Pass 4: 29 swaps with 37. Total 3. Counting a swap in every pass gives n − 1 = 4.

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

Exams that ask this topic