Arrange the following in order related to bubble sort for a list of elements:
4 -9 12 30 2 6
(A).
-9 4 12 30 2 6
(B).
-9 4 12 2 30 6
(C).
-9 4 2 12 6 30
(D).
-9 4 12 2 6 30
Arrange the following in order related to bubble sort for a list of elements:
| 4 | -9 | 12 | 30 | 2 | 6 |
|---|
(A).
| -9 | 4 | 12 | 30 | 2 | 6 |
|---|
(B).
| -9 | 4 | 12 | 2 | 30 | 6 |
|---|
(C).
| -9 | 4 | 2 | 12 | 6 | 30 |
|---|
(D).
| -9 | 4 | 12 | 2 | 6 | 30 |
|---|
Solution
(A) -9, 4, 12, 30, 2, 6: in the first pass, 4 and -9 are compared and swapped.
(B) -9, 4, 12, 2, 30, 6: 30 and 2 are swapped, since 4 < 12 and 12 < 30 need no swap.
(D) -9, 4, 12, 2, 6, 30: 30 and 6 are swapped, so the largest element 30 reaches its final place and the first pass ends.
(C) -9, 4, 2, 12, 6, 30: in the second pass, 12 and 2 are swapped (4 and 12 needed no swap).
Bubble sort compares adjacent pairs from the left and swaps them if they are out of order, so each pass pushes the largest remaining element to the end.
Related questions:
2026: 21 May Shift 1
2026: 18 May Shift 2
2026: 23 May Shift 1
2025: 3 June Shift 2
2026: 19 May Shift 1