Identify the number of swaps required in the first pass of bubble sort for the following list :-
list= [8, 7, 13, 1, -9, 4]
Identify the number of swaps required in the first pass of bubble sort for the following list :-
list= [8, 7, 13, 1, -9, 4]
Solution
✅ Correct Option: 2
In the first pass, bubble sort compares each adjacent pair from left to right and swaps the pair whenever the left element is larger.
| Comparison | Swap? | List after comparison | Swaps so far |
|---|---|---|---|
| 8 and 7 | Yes | [7, 8, 13, 1, -9, 4] | 1 |
| 8 and 13 | No | [7, 8, 13, 1, -9, 4] | 1 |
| 13 and 1 | Yes | [7, 8, 1, 13, -9, 4] | 2 |
| 13 and -9 | Yes | [7, 8, 1, -9, 13, 4] | 3 |
| 13 and 4 | Yes | [7, 8, 1, -9, 4, 13] | 4 |
The largest element, 13, moves to the end in this pass.
Related questions:
2026: 23 May Shift 2
2026: 18 May Shift 2