Home / Computer science / Master theorem
Merge sort example
The merge sort algorithm
- divides its input into two halves per recursive call
- enumerates its input during the merge step
which gives
\begin{align*} a & = 2 \\ b & = 2 \quad \iff \quad n / b = n / 2 \\ d & = 1 \quad \iff \quad \mathcal{O}(n^d) = \mathcal{O}(n^1) \end{align*}and so
\begin{equation*} a \stackrel{?}{=} b^d \quad \iff \quad 2 \stackrel{?}{=} 2^1 \quad \iff \quad 2 \stackrel{\checkmark}{=} 2 \end{equation*}and so
\begin{align*} T(n) & = a T(n / b) + \mathcal{O}(n^d) \\ & = n^d \log n \\ & = n^d \log n = n^1 \log n \\ & = \boxed{n \log n}. \end{align*}