A recursive, divide-and-conquer sorting algorithm.

Time complexity

Worst-case performance:

Abstract

Merge sort operates by recursively splitting the list into half until it is divided into the smallest possible unit, then merging them back together from the ground up through comparison.

Implementation


Time analysis

Lets discuss worst case , where is input lengh, and is number of “layers” merge sort is called such that each comparison is thus overall is

With master algo:

Each layer, the worst case is something like [1,3,5] merged with [2,4,6] in alternating order, as such there is checks during the merge process There are 2 branches per call of merge sort. Thus

With Master Theorem

Disregarding constant terms:

As

Best case is