Exercise generation and helpful materials for the Introduction to Algorithms and Data Structures 📚
Mergesort is an efficient, stable and comparison-based algorithm. Like QuickSort, MergeSort is based on the divide and conquer principle.
Most MergeSort implementations are recursive and separate the input sequence with later merge-back of the sub-sequences.
The complexity of MergeSort is pretty straight-forward as opposed to e.g. RadixSort.
As you can see it is not able to break the lower bound of O(n log(n))
, due to it being
comparison-based.
Best | Average | Worst | Stability |
---|---|---|---|
Ω(n log(n)) |
Θ(n log(n)) |
O(n log(n)) |
yes |