Analysis of naïve divide-and-conquer multiplication [00PX]
This divide-and-conquer multiplication algorithm involves four recursive calls to \mathsf {mul} on inputs of size n/2, two shifts (which take constant time), and three n-bit additions (which take \Theta (n)). Hence we can write a recurrence for the time M(n) taken by \mathsf {mul} on n-bit inputs: \begin {align*} M(1) &= \Theta (1) \\ M(n) &= 4M(n/2) + \Theta (n) \end {align*} But what is a closed form for M(n)? Is it better than n^2?
We can unroll this recurrence into a recursion tree to figure out how much total work happens.
- At the root, an amount of work happens proportional to the input size, n.
- At the first level of recursion, there are four recursive calls, each on n/2-bit numbers, giving a total something like 4 \cdot (n/2) = 2n.
- At the second level, there are sixteen recursive calls on n/4-bit inputs, giving a total of 4n.
- In general, at depth k, there are 4^k recursive calls, each on an input of size n/2^k, for a total of 4^k \cdot n/2^k = 2^k n.