#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · ANIMATED

Sorting Visualizer: Watch Six Sorting Algorithms Step by Step

See how each sorting algorithm moves the numbers, and count its comparisons and swaps.

  • 📶 6 algorithms
  • ⏯️ Play, pause or step
  • 🔢 Real comparison counts

How to use the Sorting Algorithm Visualizer

  1. 1. Choose an algorithmPick bubble, selection, insertion, merge, quick or heap sort.
  2. 2. Set the dataUse a random array or type your own numbers.
  3. 3. Start or stepPlay the animation or go one step at a time and read the counts.

Worked example: bubble sort on 5, 1, 4, 2, 8

Type 5, 1, 4, 2, 8 as your own values and pick bubble sort. Bubble sort compares neighbours and swaps them if they are in the wrong order, so the largest value "bubbles" to the end each pass:

  • Pass 1: 4 comparisons, 3 swaps → 1 4 2 5 8
  • Pass 2: 3 comparisons, 1 swap → 1 2 4 5 8
  • Pass 3: 2 comparisons, no swaps → the array is sorted, so it stops early.

The visualizer ends with 9 comparisons and 4 swaps. Selection sort on the same input always makes 10 comparisons (4 + 3 + 2 + 1), because it never stops early, which is why its best case is still O(n²).

Comparing the six algorithms

  • Bubble and insertion: O(n²) on average but O(n) on nearly sorted data. Insertion sort is used inside faster sorts for small pieces.
  • Selection: always O(n²) comparisons but at most n − 1 swaps.
  • Merge: O(n log n) every time and stable, but needs extra memory. The counter shows writes instead of swaps.
  • Quick (last element as pivot): O(n log n) on average and very fast in practice, but O(n²) on already sorted input with this pivot choice.
  • Heap: O(n log n) with no extra memory, but not stable.

Try sorted input such as 1, 2, 3, 4, 5, 6, 7, 8 on quick sort and watch the comparison count jump. That is the worst case examiners like to ask about.

Frequently asked questions

What does stable mean?

A stable sort keeps equal values in their original order. It matters when you sort records by one field after sorting by another.

Why is merge sort showing writes, not swaps?

Merge sort copies values back from temporary lists instead of swapping pairs, so counting writes is the honest measure.

Which sort does Python or Java use?

Python's sorted() and Java's sort for objects use Timsort, a mix of merge and insertion sort. Java uses a dual-pivot quick sort for primitive arrays.

Is the visualizer free?

Yes. Choose settings freely; the first Start asks for your name and WhatsApp number once, and every Uncodemy tool stays free and open after that.

More free tools

See all free tools