Sorting

Sorting Algorithms Visualizer

Explore different sorting algorithms and understand how they work, step-by-step. Click on any algorithm below to start the visualization!

Bubble sort

Bubble Sort

Compares adjacent elements and swaps them if they're in the wrong order.

Selection sort

Selection Sort

Finds the smallest element in the array and places it at the front.

Insertion sort

Insertion Sort

Builds the sorted array by inserting elements in their correct position.

Merge sort

Merge Sort

Divides the array, sorts them, and merges them back together.

Quick sort

Quick Sort

Uses a pivot to partition the array and sorts each partition.

Heap sort

Heap Sort

Transforms the array into a heap structure and sorts it.

Radix sort

Radix Sort

Sorts numbers by processing individual digits from least to most significant.

Shell sort

Shell Sort

Sorts elements by comparing elements at a gap and reducing the gap over time.

Summary

Summary

Summary of all the sorting algorithms their worst, average and best case complexities in one table.

What Are Sorting Algorithms?

A sorting algorithm is a method for reorganizing a collection of items such as numbers, letters, or records into a specific order, typically ascending or descending. Sorting is one of the most fundamental operations in computer science, forming the backbone of efficient data retrieval, search operations, and data processing pipelines.

Whether you are a student learning data structures for the first time, a developer preparing for technical interviews, or a professional brushing up on algorithm fundamentals, understanding sorting algorithms is essential. Each algorithm has unique properties in terms of time complexity, space complexity, and real-world applicability.

Why Learn Sorting Algorithms Visually?

Sorting algorithms can be difficult to grasp from text or pseudocode alone. That's exactly why EasySorting was created to let you see each algorithm in action, pass by pass, comparison by comparison. You can:

Sorting Algorithms Covered

EasySorting covers 8 major sorting algorithms, each explained with history, time and space complexity, pseudocode, and step-by-step visualization:

Which Sorting Algorithms Do Real Languages Actually Use?

Here's the part most courses skip: none of the major programming languages ship a plain textbook algorithm. Production sort functions are hybrids that combine several of the algorithms you can visualize on this site:

Notice the pattern: insertion sort, often dismissed as a "slow beginner algorithm", appears inside nearly every production hybrid, because for small arrays its low overhead beats the clever algorithms. And merge sort lives on inside Timsort because it is stable. The "best" algorithm isn't one algorithm at all — it's knowing when each one wins, which is exactly what the visualizers here help you build an intuition for.

Frequently Asked Questions

Which sorting algorithm is the fastest?

It depends on the data. For random data, quick sort is usually fastest in practice thanks to cache-friendly partitioning. Merge sort guarantees O(n log n) even in the worst case. For nearly sorted data, insertion sort approaches O(n) and beats them both. And for bounded integer keys, radix sort can beat every comparison sort.

Why do schools still teach bubble sort if nobody uses it?

Because it is the clearest possible introduction to the core ideas — comparisons, swaps, passes, and loop invariants — in about five lines of code. You learn to reason about algorithms on bubble sort, then apply that reasoning to the ones that actually get used.

What is the difference between stable and unstable sorting?

A stable sort keeps items with equal keys in their original relative order. That matters whenever you sort by more than one field — for example, sorting employees by department after sorting by name only works correctly if the second sort is stable. Merge sort, insertion sort, and Timsort are stable; quick sort, heap sort, and selection sort are not.

Can anything sort faster than O(n log n)?

Not by comparing elements — O(n log n) is a proven mathematical lower bound for comparison-based sorting. But algorithms that don't compare, like counting sort and radix sort, sidestep the bound entirely and reach linear time when the key range is limited.

Click on any algorithm above to begin the interactive visualization. Happy Learning! 🎉