Skip to main contentSkip to solution

In bubble sort, how many passes will be needed to sort the array [12, 17, 34, 8]?

Solution

✅ Correct Option: 2

The smallest element, 8, is at the end, so each pass moves it only one place to the left. Bubble sort needs n−1=3n - 1 = 3 passes here.

PassSwaps madeArray after pass
1(34, 8)[12, 17, 8, 34]
2(17, 8)[12, 8, 17, 34]
3(12, 8)[8, 12, 17, 34]

The array is fully sorted after the 3rd pass.


Option 3: nn passes is not needed, since after n−1n - 1 passes the last remaining element is already in place.

Option 4 and 5: a 4th pass would only be a check that finds no swaps, and it is not required for sorting.

Keyboard Shortcuts

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