🔀Sorting Algorithm Visualizer

Pick an algorithm and press play — watch bars compare, swap, and sort in real time with speed and size you control.

0 comparisons 0 swaps Step 0 / 0 Ready

Sorting Algorithm Visualizer Online — Free & Interactive

Want to actually see how sorting algorithms work? Our free Sorting Algorithm Visualizer animates them step by step the moment you press play. As a clear, interactive sorting algorithm visualizer, it shows a set of bars being compared, swapped, and ordered in real time—so abstract pseudocode turns into something you can watch and understand.

Compare the classics side by side: bubble, selection, insertion, merge, quick, and heap sort, each with comparisons and swaps highlighted as they happen. Adjust the array size and animation speed, generate a fresh random array, and step through or play the whole run. Each algorithm comes with its best, average, and worst-case time complexity, so you see not just how it sorts but how efficiently. Whether you're a student, a teacher, or prepping for interviews, it makes algorithms click.

Simply pick an algorithm and press play. No sign-up, no downloads, no limits—just clear visual learning whenever you need it.

Algorithm Complexity Reference

Bubble Sort

BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)
Stable

Selection Sort

BestO(n²)
AverageO(n²)
WorstO(n²)
SpaceO(1)
Unstable

Insertion Sort

BestO(n)
AverageO(n²)
WorstO(n²)
SpaceO(1)
Stable

Merge Sort

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)
Stable

Quick Sort

BestO(n log n)
AverageO(n log n)
WorstO(n²)
SpaceO(log n)
Unstable

Heap Sort

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(1)
Unstable

About the Sorting Algorithm Visualizer

Key features

Six algorithms

Bubble, selection, insertion, merge, quick, and heap sort — the full set covered in most CS courses and interview prep guides.

Comparison & swap highlighting

Bars turn amber during comparisons and red during swaps or writes, so your eye naturally follows what the algorithm is doing.

Play, pause, step, and reset

Full playback controls so you can study each operation individually or watch the whole sort at a glance — and reset back to the original array any time.

Adjustable size and speed

Set the array anywhere from 5 to 100 elements and the speed from a deliberate one-step-per-600ms all the way to near-instant at 5ms per step.

Live stats

A stats bar tracks the step count, comparison count, and swap count in real time — making the O(n²) vs O(n log n) difference tangible.

Big-O complexity reference

Each algorithm shows its best, average, and worst-case time complexity and whether it is stable — connecting the animation to the theory.

Why visualising helps

Reading pseudocode for bubble sort tells you that it compares adjacent elements repeatedly. Watching it sort a 30-element array makes it obvious why 900 operations are needed — you see every redundant comparison, every small bubble drifting slowly to the right. That intuition sticks in a way that a paragraph of text rarely does.

Merge sort's efficiency becomes equally obvious: the array splits, sorts its halves, and merges them back in a fraction of the comparisons, the pattern of green regions spreading outward from sub-arrays until the whole thing is done. Quick sort's pivot behaviour — how a good or bad pivot choice affects the number of swaps — is something you have to see to truly understand why its worst case is O(n²).

That's why this tool exists. Algorithms that look identical in terms of their interface — take an array, return a sorted array — have dramatically different internal behaviour. Seeing that behaviour is the fastest path to understanding it.

Who it's for

CS students

Follow your lecture notes with a live animation alongside — step through the exact comparisons and swaps your textbook describes.

Educators and teachers

Embed or link the tool from lecture slides, course notes, or class websites. It's free, no-account, and works on any device.

Interview candidates

Solidify your Big-O intuition before coding interviews by watching the difference between O(n²) and O(n log n) algorithms on the same data.

Curious learners

No prerequisites needed — just pick an algorithm and press play. The visual is self-explanatory even without a CS background.

Frequently Asked Questions

How does the sorting visualizer work?

Pick an algorithm and press play; the tool animates an array of bars, highlighting each comparison and swap as the algorithm sorts them, so you can watch exactly how it reorders the data.

Is this visualizer free to use?

Yes, it's completely free with no sign-up, downloads, or limits. Run as many visualisations as you like.

Which sorting algorithms are included?

It covers the common ones taught in computer science: bubble sort, selection sort, insertion sort, merge sort, quick sort, and heap sort.

Can I control the speed and array size?

Yes. You can adjust the animation speed (1 = slowest to 5 = fastest) and the number of bars (5 to 100), and generate a fresh random array whenever you like, so you can slow things down to follow each step or speed through a large array.

Can I step through one operation at a time?

Yes. Alongside play and pause, you can use the Step button to advance through the algorithm one operation at a time — useful for studying each individual comparison and swap closely.

Does it show time complexity?

Yes. Each algorithm card below the visualizer shows its best, average, and worst-case time complexity (Big-O) and whether it is stable, so you can connect what you see to how efficiently the algorithm performs in different scenarios.

Why do some algorithms finish much faster than others?

Different algorithms do different amounts of work. For example, bubble sort makes many comparisons and swaps (O(n²) on average), while merge sort and quick sort are generally far more efficient (around O(n log n)). The visualizer makes that difference visible — try the same array with bubble sort and merge sort and watch the step counter.

Is my data stored anywhere?

No. Everything runs directly in your browser — the arrays are generated and sorted locally. Nothing is sent to a server or stored anywhere.

Does it work on mobile devices?

Yes, the tool is fully responsive and the visualisation scales to fit smartphones, tablets, and desktops without overflowing the screen. On small screens, the default array size is reduced automatically so the bars remain readable.

Can I use this for teaching or in my own materials?

Yes — it's built to be a clear learning aid for students, teachers, and anyone studying algorithms. Feel free to link to it from your notes, lessons, blog posts, or course materials.