A multiplication algorithm is an algorithm (or method) to multiply two numbers. Depending on the size of the numbers, different algorithms are more efficient than others. Numerous algorithms are known and there has been much research into the topic. The oldest and simplest method, known since antiquity as long multiplication or grade-school multiplication, consists of multiplying every digit in the first number by every digit in the second and adding the results. This has a time complexity of O ( n 2 ) {\displaystyle O(n^{2})} , where n is the number of digits. When done by hand, this may also be reframed as grid method multiplication or lattice multiplication. In software, this may be called "shift and add" due to bitshifts and addition being the only two operations needed. In 1960, Anatoly Karatsuba discovered Karatsuba multiplication, unleashing a flood of research into fast multiplication algorithms. This method uses three multiplications rather than four to multiply two two-digit numbers. (A variant of this can also be used to multiply complex numbers quickly.) Done recursively, this has a time complexity of O ( n log 2 3 ) {\displaystyle O(n^{\log _{2}3})} . Splitting numbers into more than two parts results in Toom–Cook multiplication; for example, using three parts results in the Toom-3 algorithm. Using many parts can set the exponent arbitrarily close to 1, but the constant factor also grows, making it impractical. In 1968, the Schönhage–Strassen algorithm, which makes use of a Fourier transform over a modulus, was discovered. It has a time complexity of O ( n log n log log n ) {\displaystyle O(n\log n\log \log n)} . In 2007, Martin Fürer proposed an algorithm with complexity O ( n log n 2 Θ ( log ∗ n ) ) {\displaystyle O(n\log n2^{\Theta (\log ^{*}n)})} . In 2014, Harvey, Joris van der Hoeven, and Lecerf proposed one with complexity O ( n log n 2 3 log ∗ n ) {\displaystyle O(n\log n2^{3\log ^{*}n})} , thus making the implicit constant explicit; this was improved to O ( n log n 2 2 log ∗ n ) {\displaystyle O(n\log n2^{2\log ^{*}n})} in 2018. Lastly, in 2019, Harvey and van der Hoeven came up with a galactic algorithm with complexity O ( n log n ) {\displaystyle O(n\log n)} . This matches a guess by Schönhage and Strassen that this would be the optimal bound, although this remains a conjecture today. Integer multiplication algorithms can also be used to multiply polynomials by means of the method of Kronecker substitution.
Long multiplication If a positional numeral system is used, a natural way of multiplying numbers is taught in schools as long multiplication, sometimes called grade-school multiplication, sometimes called the Standard Algorithm: multiply the multiplicand by each digit of the multiplier and then add up all the properly shifted results. It requires memorization of the multiplication table for single digits. This is the usual algorithm for multiplying larger numbers by hand in base 10. A person doing long multiplication on paper will write down all the products and then add them together; an abacus-user will sum the products as soon as each one is computed.
Example This example uses long multiplication to multiply 23,958,233 (multiplicand) by 5,830 (multiplier) and arrives at 139,676,498,390 for the result (product).
23958233 × 5830 ——————————————— 00000000 ( = 23,958,233 × 0) 71874699 ( = 23,958,233 × 30) 191665864 ( = 23,958,233 × 800) + 119791165 ( = 23,958,233 × 5,000) ——————————————— 139676498390 ( = 139,676,498,390)
Other notations In some countries such as Germany, the above multiplication is depicted similarly but with the original product kept horizontal and computation starting with the first digit of the multiplier:
23958233 · 5830 ——————————————— 119791165 191665864 71874699 00000000 ——————————————— 139676498390
Below pseudocode describes the process of above multiplication. It keeps only one row to maintain the sum which finally becomes the result. Note that the '+=' operator is used to denote sum to existing value and store operation (akin to languages such as Java and C) for compactness.
… excerpt ends here. Continue reading the full article.



