Skip to content
SimpleScope

Sorting

Bubble sort vs Quick sort

Bubble sort and Quick sort both put an array in order, in different ways. Bubble sort: swap neighbors that are out of order. Quick sort: divide and conquer: partition around a pivot. In the worst case both take O(n²), so the choice comes down to the other differences below.

At a glance

PropertyBubble sortQuick sort
TechniqueSwap neighbors that are out of orderDivide and conquer: partition around a pivot
Best case timeO(n)O(n log n)
Average case timeO(n²)O(n log n)
Worst case timeO(n²)O(n²)
Extra spaceO(1)O(log n)
Stable (equal values keep their order)YesNo
In place (no extra array)YesYes
Needs sorted inputNoNo

When to choose each

Choose bubble sort when

you want the simplest sort to explain, on tiny or almost sorted data.

Avoid it when

the data is large.

Choose quick sort when

you want a fast in-place sort on typical data.

Avoid it when

you need a worst-case guarantee or a stable sort.

The same inputs, counted

These numbers come from running both real implementations: operations (comparisons plus writes, a swap counting as two writes).

InputBubble sortQuick sort
Mixed4031
Already sorted675
Reversed6351
Nearly sorted1365
Duplicates4729

See them run

More comparisons