Bubble Sort vs Quick Sort

Across our 3 test inputs, Quick Sort needed 106 comparisons in total versus 135 for Bubble Sort. On average Bubble Sort runs in O(n²) time and Quick Sort in O(n log n). Bubble Sort is stable; Quick Sort is not.

Head-to-head on identical inputs (comparisons)

InputBubble SortQuick Sort
Random order4522
Nearly sorted4539
Reversed4545

Complexity

Bubble SortQuick Sort
Average timeO(n²)O(n log n)
Worst timeO(n²)O(n²)
SpaceO(1)O(log n)
StableYesNo

When to use Bubble Sort

Educational purposes and very small arrays. Never use in production due to O(n²) worst-case.

When to use Quick Sort

General-purpose sorting. Fast in practice due to excellent cache locality. Default algorithm used in many language libraries (often hybridised as Introsort).