Sorting Algorithm Animator
Visualize sorting algorithms step-by-step with comparisons and swaps
Configuration
Sorting Algorithm:
Bubble Sort
Insertion Sort
Selection Sort
Merge Sort
Quick Sort
Heap Sort
Array Size:
20
Animation Speed:
50
Initial Array:
Random
Nearly Sorted
Reversed
Generate Array
Start Sorting
Step
Reset
Visualization
Ready
Comparisons
0
Swaps
0
Array Accesses
0
Time Complexity
-
Help
Color Coding
Blue:
Default/unsorted elements
Red:
Elements being compared
Yellow:
Elements being swapped
Green:
Sorted/in correct position
Purple:
Pivot element (Quick Sort)
Algorithm Descriptions
Bubble Sort (O(n²)):
Repeatedly swaps adjacent elements if they're in wrong order. Simple but inefficient.
Insertion Sort (O(n²)):
Builds sorted array one element at a time. Efficient for small or nearly sorted data.
Selection Sort (O(n²)):
Finds minimum element and places it at the beginning. Always makes n-1 swaps.
Merge Sort (O(n log n)):
Divides array in half, recursively sorts, then merges. Stable and predictable.
Quick Sort (O(n log n) avg):
Picks pivot, partitions around it, recursively sorts. Fast in practice.
Heap Sort (O(n log n)):
Builds max heap, then repeatedly extracts maximum. In-place but not stable.
When to Use Each Algorithm
Bubble/Insertion/Selection:
Educational purposes, very small arrays, or nearly sorted data (insertion)
Merge Sort:
When you need stable sorting or predictable O(n log n) performance
Quick Sort:
General purpose sorting - fastest on average for large random arrays
Heap Sort:
When you need O(n log n) worst case with O(1) space (in-place)