Long multiplication
The most straight-forward way to do multiplication is by long multiplication as we learned in elementary school
Example
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)
It's easy to conclude that multiplying two -digit numbers using long multiplication requires single-digit operations (additions and multiplications)
Karatsuba multiplication
Karatsuba multiplication is an efficient algorithm for multiplying large numbers. The algorithm reduces the multiplication of two -digit numbers to at most single-digit multiplications in general
Procedure
Given two numbers and represented as:
where and are the lower halves, and and are the upper halves of the numbers, each of length .
The product can be computed as follows:
- Compute three products:
- Combine the results:
Example
If we need to multiply 1234 and 5678 using Karatsuba multiplication.
- Split the numbers:
- Compute the three products:
- Combine the results:
Thus, .
Schönhage–Strassen algorithm
(status:: todo)