In bubble sort, how many passes will be needed to sort the array [12, 17, 34, 8]?
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 passes here.
| Pass | Swaps made | Array 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: passes is not needed, since after 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.
Related questions:
2025: 30 May Shift 2
2026: 18 May Shift 2
2025: 15 May Shift 2