Algorithms - CMSC-272XX Divide and Conquer: The Karatsuba Algorithm (Multiplication of Large Integers)
Algorithms - CMSC-272XX Divide and Conquer: The Karatsuba Algorithm (Multiplication of Large Integers)
Updated 01-13-2021
NOTATION. In this note, log will always mean log2 (base-2 logarithm).
Procedure Karatsuba(X, Y )
3. X =: 10n/2 X1 + X2
4. Y =: 10n/2 Y1 + Y2
6. U := Karatsuba(X1 , Y1 )
7. V := Karatsuba(X2 , Y2 )
1
8. W := Karatsuba(X1 − X2 , Y1 − Y2 )
9. Z := U + V − W
12. return P
M (n) = 3i M (n/2i ).
where the term 3T (n/2) comes, as before, from lines 6,7,8; the additional
O(n) term is the number of digit-additions required to perform the additions
2
and subtractions in lines 9 and 10. The O(n) term also includes bookkeeping
costs.
We shall learn later how to analyse recurrences of the form (2). It turns
out that the additive O(n) term does not change the rate of growth, and
the result will still be
T (n) = O(nlog 3 ). (3)
Comment: While this was not the last word on the complexity of integer
multiplication (methods based on Fast Fourier Transform are even faster),
it inspired a lot of further progress, including Strassen’s fast matrix multi-
plication.