Escolar Documentos
Profissional Documentos
Cultura Documentos
This lecture note has been modified from lecture note for 23250 by Prof. Francis Chin
Assume n=2m, we treat x and y as two n-bit strings and partition them into two halves as x = a * b, y= c * d, i.e., concatenation of a, b and c, d. As binary numbers, we can express
xy = (a2n/2 + b) (c2n/2 + d) = ac2n + (ad + bc) 2n/2 + bd ............ (*) The above computation of xy reduces to four multiplications of (n/2)-bit numbers plus some additions and shifts (multiplications by powers of 2).
Let T(n) be the number of bit-operations required to multiply two n-bit numbers.
Thus T(n) depends very much the number of subproblems and also the size of the subproblems. If the number of subproblems were 1, 3, 4, 8, then the algorithms would be of order n, nlog3, n2, n3 respectively.
A better Algorithm
So, the multiplication of two n-bit numbers remains O(n2) if the number of half-size subproblems remains 4 In order to reduce the time complexity, we attempt to reduce the number of subproblems (i.e., multiplications ) by a trick which uses more additions and shifts, specifically,by reducing one multiplication with many additions and shifts. This trick pays off asymptotically, i.e., when n is large.
Analysis
One can use the multiplication routine recursively to evaluate the products u, v, and w. The additions and shifts require O(n) time. Thus the time complexity of multiplying two n-bit numbers is bounded from above by
where k is a constant reflecting the additions and shifts. From the above discussion, the solution to the recurrence is then O(n log3) = O(n 1.59).
10
Example
This divide and conquer technique for multiplication of two nbit number can also applied to the multiplication problem of two n-digit integers and n-degree polynomial.
11
MATRIX MULTIPLICATION
The matrix multiplication can be performed as follows:
This formulation divides the n x n matrix into n/2 x n/2 matrix, and divide the problem into 8 subproblem of size n/2. (Note that n is used as the input size even though n2 is the input size ofthe matrix.) This gives the following recurrence,
March 25, 2012 12
Recurrence Relation
T(n) remains O(n3). However, the matrix multiplication can also be computed as follows.
13
15