← Back to Programming Tools

📊 Sorting Algorithm Visualizer

Visualize and understand sorting algorithms with interactive animations

Comparisons
0
Swaps
0
Array Accesses
0
Time Elapsed
0ms

Bubble Sort - Time Complexity

Best Case O(n)
Average Case O(n²)
Worst Case O(n²)
Space O(1)

JavaScript Implementation

// Select an algorithm and click "Export Code" to see the implementation

📖 How to Use Sorting Visualizer

Watch sorting algorithms come to life with animated visualizations. Perfect for students learning algorithms or developers understanding time complexity:

1 Choose Sorting Algorithm

Select from Bubble Sort, Quick Sort, Merge Sort, Insertion Sort, Selection Sort, or Heap Sort. Each has different time complexity and use cases.

2 Set Array Size and Speed

Adjust array size (10-100 elements) and animation speed (slow/medium/fast). Smaller arrays show details better, while larger ones demonstrate efficiency differences.

3 Watch the Animation

Click "Start Sort" to see the algorithm in action. Color-coded bars show comparisons, swaps, and sorted elements in real-time. Use pause/resume controls to study specific steps.

4 Analyze Performance

View comparison count, swaps, and time taken. Export the JavaScript implementation to use in your own projects.

❓ Frequently Asked Questions

Quick Sort and Merge Sort are generally fastest for large datasets (O(n log n) average). Bubble Sort and Selection Sort are slowest (O(n²)). However, "best" depends on your data: nearly-sorted arrays perform well with Insertion Sort.
Blue/default bars are unsorted elements. Red/purple bars are currently being compared. Green indicates sorted elements in their final position. Yellow shows elements being swapped. Colors help you understand the algorithm's decision-making process.
Absolutely! Watch how algorithms work step-by-step to build intuition. Practice explaining time/space complexity while observing performance. Export code snippets to study implementation details. Many interview questions involve sorting concepts.
Quick Sort's performance depends on pivot selection. Poor pivots (like always choosing the first element in a sorted array) lead to O(n²) worst case. Merge Sort guarantees O(n log n) but uses more memory. Our visualizer uses random pivot selection for better average performance.
Stable sorts (Merge, Insertion) preserve the relative order of equal elements. Unstable sorts (Quick, Heap, Selection) may change the order. This matters when sorting objects with multiple properties. Our tool focuses on numeric arrays where stability is less critical.