Apply bubble sort technique to sort list of elements given below:
numList2 = [2, 7, 5, 8, 4]
In which pass the last swap happens?
Apply bubble sort technique to sort list of elements given below:
numList2 = [2, 7, 5, 8, 4]
In which pass the last swap happens?
Solution
✅ Correct Option: 3
Bubble sort compares adjacent elements and swaps them if they are out of order.
| Pass | Swaps made | List after the pass |
|---|---|---|
| 1 | and | [2, 5, 7, 4, 8] |
| 2 | [2, 5, 4, 7, 8] | |
| 3 | [2, 4, 5, 7, 8] | |
| 4 | none | [2, 4, 5, 7, 8] |
The list becomes sorted in Pass 3, so the last swap happens there.
Option 4: Pass 4 is only needed to confirm that the list is sorted. No swap occurs in it.
Related questions:
2025: 16 May Shift 1
2026: 23 May Shift 2
2026: 29 May Shift 2