Given the array [12, 8, 20, 10]
What will be the sequence of the elements in the array after the first pass using bubble sort?
(A) 12
(B) 8
(C) 20
(D) 10
Given the array [12, 8, 20, 10]
What will be the sequence of the elements in the array after the first pass using bubble sort?
(A) 12
(B) 8
(C) 20
(D) 10
Solution
✅ Correct Option: 2
In one pass of bubble sort, adjacent elements are compared from left to right and swapped if the left one is larger.
| Comparison | Action | Array after |
|---|---|---|
| 12 and 8 | swap | 8, 12, 20, 10 |
| 12 and 20 | no swap | 8, 12, 20, 10 |
| 20 and 10 | swap | 8, 12, 10, 20 |
The array is 8, 12, 10, 20, which is (B), (A), (D), (C).
Option 3: stops after the first swap and misses the 20 and 10 swap.
Option 4: misses the first swap of 12 and 8.
The largest element (20) always reaches the last position after the first pass.
Related questions:
2025: 14 May Shift 1
2025: 16 May Shift 1
2025: 14 May Shift 1
2025: 16 May Shift 1
2026: 24 May Shift 1