Skip to main contentSkip to solution

Consider the following list= [8, 7, 13, 1, -9, -14]. Arrange the iterations of the first pass of the Selection Sort algorithm given below in ascending order of the iterations.

(A). [-14, 8, 13, 7, 1, -9]

(B). [-9, 8, 13, 7, 1, -14]

(C). [1, 8, 13, 7, -9, -14]

(D). [7, 8, 13, 1, -9, -14]

Solution

✅ Correct Option: 2

The algorithm compares the first element with each later element and swaps whenever the later element is smaller. Each swap gives a new state of the list.

(D) [7, 8, 13, 1, -9, -14]: 7 is smaller than 8, so they swap.

(C) [1, 8, 13, 7, -9, -14]: 13 causes no swap, then 1 is smaller than 7, so they swap.

(B) [-9, 8, 13, 7, 1, -14]: -9 is smaller than 1, so they swap.

(A) [-14, 8, 13, 7, 1, -9]: -14 is smaller than -9, so they swap, which ends the first pass.

The first position now holds the smallest element, -14.

Keyboard Shortcuts

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