Step 1

Choose an algorithm

Switch anytime before starting

Ready
Ready to sort

Now visualizing

Bubble Sort

Compare neighboring values and move the largest unsorted value to the right.

Comparisons
0
Swaps
0
Time
0.00s
Current Array 18 values

    Reference

    Algorithm Comparison

    n = number of elements

    Best, average, and worst time complexity and space complexity for six sorting algorithms
    Algorithm Best Average Worst Space
    Bubble Sort O(n) O(n²) O(n²) O(1)
    Selection Sort O(n²) O(n²) O(n²) O(1)
    Insertion Sort O(n) O(n²) O(n²) O(1)
    Merge Sort O(n log n) O(n log n) O(n log n) O(n)
    Quick Sort O(n log n) O(n log n) O(n²) O(log n)*
    Heap Sort O(n log n) O(n log n) O(n log n) O(1)

    * Quick Sort uses O(log n) auxiliary space on average. Recursion can grow to O(n) with consistently unbalanced pivots.