Sorting Algorithm Animation
Watch Bubble, Selection and Insertion Sort order 5-50 bars, one comparison or swap per step. Play, pause, or step forward and back through every move.
Still loading. If the tool doesn’t appear, reload this page.
Planned features and workflows
- AltF CodeVisualizer
Coming soon
About this tool
Sorting Algorithm Animation
Watch Bubble Sort, Selection Sort and Insertion Sort step through an animated bar chart, one comparison and swap at a time.
A sorting algorithm animation shows each comparison and swap as bars changing places. This one replays Bubble, Selection and Insertion Sort on the same random array of 5 to 50 bars: compared pairs turn amber, bars in their final position turn green, and you can play, pause or step forward and back one move at a time.
How to use Sorting Algorithm Animation
Choose an algorithm with the Bubble Sort, Selection Sort or Insertion Sort buttons; Bubble Sort is selected first.
Set the Size slider from 5 to 50 bars (default 15) and the Speed slider from 1% to 100% (default 50%), then press New Array for a fresh random set.
Press Sort to record every step of the chosen algorithm and start the bar-chart animation, with a Step x/y counter beside the algorithm name.
Follow the bars: compared pairs are marked ▲ and swaps ⇄, bars already in their final position turn green with ✓, and the status line describes the current step.
Use the controls under the chart to jump back to the first step, step back or forward one move at a time, or Play and Pause the animation.
Why use Sorting Algorithm Animation
Every comparison is a step you can rewind
The full sequence is generated up front, so you can scrub backwards and forwards or jump to the start, not just watch an animation run once.
Colour marks the invariant, not just the swap
Amber shows the pair currently being compared and green shows only the positions that can no longer change — the tail for Bubble Sort, the front for Selection Sort, and nothing for Insertion Sort until the last step, because its sorted prefix can still shift.
Same array, three algorithms
Switching algorithm re-sorts the array you are already looking at, so the comparison is like for like instead of against fresh random data.
Common use cases
- You are revising for an algorithms exam and cannot picture why selection sort makes the same number of comparisons on sorted and reverse-sorted input — stepping through both cases makes the difference obvious.
- You are teaching a class and want to pause mid-pass on a 15-bar array to ask which element the inner loop will touch next, before pressing step forward to check the answer.
- You are writing lecture notes on quadratic sorting and need to compare the step counts the three algorithms produce on the exact same random array.
Frequently asked questions
Which sorting algorithms are included?
Three: Bubble Sort, Selection Sort and Insertion Sort. All three are comparison sorts with O(n²) worst-case time complexity and sort in place, which is what makes them worth watching side by side.
Link to answerHow many bars can I sort at once?
Between 5 and 50, set with the array size slider. Values are random integers from 5 to 104, and changing the size generates a fresh array immediately.
Link to answerCan I slow the animation down?
Yes. The speed slider runs from 1% to 100%, which maps to a delay of roughly 198 ms per step at the slowest setting down to about 50 ms at the fastest. You can also pause and use the step-forward and step-back buttons to move exactly one comparison at a time.
Link to answerWhich of the three algorithms is fastest?
On random data all three do on the order of n²/2 comparisons, but insertion sort is usually fastest in practice and drops to O(n) on already-sorted input, while selection sort always performs the same number of comparisons regardless of order. None of them is competitive with O(n log n) sorts like merge sort or quicksort on large inputs.
Link to answerHow does bubble sort work step by step?
It compares each adjacent pair from left to right and swaps them when the left value is larger, so the largest remaining value ends up at the right end of every pass. This version always runs every pass with no early exit: 15 bars take 105 comparisons, shown as 106 steps including the final sorted frame.
Link to answerCan I enter my own numbers to sort?
No. The array is always random; New Array draws a fresh one and the Size slider sets how many bars it has. Switching algorithm keeps the bars on screen, so you can run all three sorts on the same data and compare the step counters.
Link to answer