For a given list= [63, 42, 21, 9, 86]. Using the bubble sort algorithm, arrange the following outputs of each iteration of the first pass in ascending order of iterations.
(A). [63, 42, 21, 9, 86]
(B). [42, 21, 63, 9, 86]
(C). [42, 63, 21, 9, 86]
(D). [42, 21, 9, 63, 86]
For a given list= [63, 42, 21, 9, 86]. Using the bubble sort algorithm, arrange the following outputs of each iteration of the first pass in ascending order of iterations.
(A). [63, 42, 21, 9, 86]
(B). [42, 21, 63, 9, 86]
(C). [42, 63, 21, 9, 86]
(D). [42, 21, 9, 63, 86]
Solution
Bubble sort compares adjacent elements and swaps them if the left one is larger. The first pass moves the largest element to the end.
(A) [63, 42, 21, 9, 86]: the starting list.
(C) [42, 63, 21, 9, 86]: 63 and 42 are swapped.
(B) [42, 21, 63, 9, 86]: 63 and 21 are swapped.
(D) [42, 21, 9, 63, 86]: 63 and 9 are swapped. The last comparison, 63 and 86, needs no swap, so the pass ends here.
Related questions:
2026: 23 May Shift 1
2026: 24 May Shift 1
2025: 21 May Shift 1