[This page is auto-generated; please prefer to read the article’s PDF Form.]
In above, we have assumed a and b to be having the same number of digits. Now, let us say, a has na digits and b has nb digits, na ≥ nb. For their multiplication, how can we benefit from the above method?
Due to the Division Theorem, there must exist integers q, r with q ≥ 1, 0 ≤ r ≤ nb − 1, such that:
|
Starting from the least-significant-digit (LSD) of a, we can divide it into q chunks of nb digits each, and one last chunk of r digits which begins at the most-significant-digit (MSD) of a. We can write a in terms of these chunks (components) as:
|
where C0,C1,…,Cq−1 have nb digits each and Cq has r digits. Note that, because of some 0 digits within a, these chunks may have redundant 0s at the beginning positions (starting at their MSD).
The product ab will be computed as:
|
That is, we will multiply each component with b, left-shift the results as required, and add them all. Note that, there are q multiplication subproblems of (nb,nb)-digits each, and 1 subproblem of (r,nb)-digits. These subproblems can be recursively solved in the same manner; the earlier described Karatsuba method will be used whenever the two operands have equal number of digits.
Copyright © 2021 Nitin Verma. All rights reserved.