Skip to content
SimpleScope

Sorting

Merge sort vs Quick sort

Merge sort and Quick sort both put an array in order, in different ways. Merge sort: divide and conquer: split, sort each half, merge. Quick sort: divide and conquer: partition around a pivot. In the worst case merge sort takes O(n log n) while quick sort takes O(n²), so merge sort scales better on large inputs.

At a glance

PropertyMerge sortQuick sort
TechniqueDivide and conquer: split, sort each half, mergeDivide and conquer: partition around a pivot
Best case timeO(n log n)O(n log n)
Average case timeO(n log n)O(n log n)
Worst case timeO(n log n)O(n²)
Extra spaceO(n)O(log n)
Stable (equal values keep their order)YesNo
In place (no extra array)NoYes
Needs sorted inputNoNo

When to choose each

Choose merge sort when

you need a guaranteed O(n log n) time or a stable sort.

Avoid it when

memory is tight.

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).

InputMerge sortQuick sort
Mixed3431
Already sorted3175
Reversed2951
Nearly sorted3165
Duplicates3229

See them run

More comparisons