Skip to main contentSkip to solution

What will be the result after 3rd pass of Bubble Sort on the array [5, 1, 4, 2, 8]?

Solution

✅ Correct Option: 4

Bubble Sort compares adjacent elements in each pass and swaps them if they are out of order.

PassSwaps madeArray after pass
15,15,1; 5,45,4; 5,25,2[1,4,2,5,8][1, 4, 2, 5, 8]
24,24,2[1,2,4,5,8][1, 2, 4, 5, 8]
3none[1, 2, 4, 5, 8]

The array is already sorted after pass 2, so pass 3 finds nothing to swap and leaves it unchanged.


Option 3: this is the array after only the 1st pass, not the 3rd.

Keyboard Shortcuts

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