Data Structures & AlgorithmsHardTCS NQT Digital · Infosys

Problem: Selection sort is applied to [4, 3, 2, 1] and the number of element moves (assignments into the array) is counted as one per swap-half, i.e. each swap counts as 2 moves. How many moves are performed?

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

Correct answer: A. 4

Selection sort swaps only when the minimum is not already in position, and each real swap counts as two assignments here. Counting every position as a swap gives a different number.

More Coding Interview Problems questions

Exams that ask this topic