Skip to main contentSkip to solution

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

✅ Correct Option: 2

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.

Keyboard Shortcuts

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