Divide-and-Conquer Algorithms

To solve a problem of size nn:

  • Divide: the problem into subproblems, each of size < nn:
  • Conquer: Solve each subproblem recursively (and independently of the other subproblems).
  • Combine/Merge the solutions to the subproblems into a solution to the original problem.

Merge Sort

To sort nn numbers:

  • If n1n \leq 1: do nothing.
  • If n2n \geq 2: divide the nn numbers arbitrarily into two sequences, both of size n/2n/2, run Merge sort twice, once for each sequence. Then merge the two sorted sequences into one sorted sequence.

In general, if we do not assume anything about the value of cc, we find T(n)2cnlog2nT(n) \leq 2c n \log_2 n

So the running time of Merge Sort is T(n)=O(nlog2n)T(n) = O(n\log_2 n) if nn is a power of two.