Simulation

Sorting Algorithm Visualizer

Visualize sorting algorithms step by step with array generation, playback controls, highlighted pseudocode, and bar-chart animation.

Array Settings

Generate an array and choose whether sorted or nearly sorted arrays should be non-decreasing or non-increasing.

2 to 50 values

Custom Array

Enter comma-separated values from 1 to 100.

Algorithm

Array Visualization

Bubble Sort (Efficient) is sorting in non-decreasing order.

Frame 1/136
Normal
Comparing
Moving / Swapping
Sorted

Bubble Sort (Efficient)

Current line is highlighted. Indentation is preserved.

swapped ← true
while swapped = true
    swapped ← false
    for i ← 0 to lastUnsorted - 1
        if array[i] > array[i + 1]
            swap(array[i], array[i + 1])
            swapped ← true
    lastUnsorted ← lastUnsorted - 1
29
0
10
1
14
2
37
3
14
4
6
5
48
6
22
7
31
8
17
9

CURRENT STEP

Start efficient bubble sort.

SPEED

700ms

TIMELINE

1

ZOOM

100%

Scroll inside the chart area to pan horizontally and vertically. Use zoom to fit more or fewer bars.