State after one pass
Warm-up · Trace the algorithm · about 3 min
Bubble sort runs on [6, 2, 7, 3, 5]. Arrange the bars as they stand after the first pass.
Example 1
Input:
{"values":[6,2,7,3,5]}
Output:
[2,6,3,5,7]
Constraints
- The trace uses the input shown.
- One pass compares each neighbouring pair once, left to right.
Learn the idea first: Bubble sort, a visual lesson.
More Bubble sort problems
- Count swaps Warm-up
- Implement bubble sort with early exit Standard
- Array after k passes Standard
- How many swaps? Standard
- Spot the bug: the last pair Standard
- Count passes until sorted Challenge