Skip to main contentSkip to solution

Identify the number of swaps required for sorting the list 'num' using selection sort.

num=[63,42,21,9]

Solution

✅ Correct Option: 2

Selection sort picks the smallest element in the unsorted part and swaps it into the next position. A swap is counted only when the minimum is not already in its place.

PassUnsorted partMinimumSwapList after pass
163, 42, 21, 9963 and 99, 42, 21, 63
242, 21, 632142 and 219, 21, 42, 63
342, 6342none, already in place9, 21, 42, 63

Total swaps =2= \boxed{2}


Option 1 (3): this counts one swap per pass for n−1=3n-1 = 3 passes, but in pass 3 the minimum 42 is already in position, so no swap is needed.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question