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]
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
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.
Related questions:
2026: 19 May Shift 1
2026: 26 May Shift 1
2025: 14 May Shift 1
2026: 23 May Shift 2