Karatsuba Algorithm — Definition, Formula & Example
The Karatsuba algorithm is a fast way to multiply two large numbers. It splits each number in half and finds the answer with three smaller multiplications instead of the four that schoolbook multiplication needs.
Let and be -digit integers in base . Write and with and . Karatsuba's method computes , , and recursively. It then uses the identity to assemble . The running time satisfies , so . Schoolbook multiplication takes .
Key Formula
Where:
- = The two numbers being multiplied
- = The high halves of x and y
- = The low halves of x and y
- = The base of the number system (10 for decimal, 2 for binary)
- = The number of digits in each low half
Worked Example
Problem: Use the Karatsuba algorithm to compute with base and split point .
Step 1: Split each number into a high half and a low half of two digits each.
Step 2: Compute the three products. Notice that you never compute or separately.
Step 3: Recover the middle coefficient by subtraction, then shift the pieces and add.
Answer: . Karatsuba used 3 smaller multiplications where the schoolbook split needs 4.
Why It Matters
Karatsuba's 1960 result was the first proof that multiplying -digit numbers takes fewer than steps. It is the standard first example of divide-and-conquer recurrences in an algorithms course. Big-number libraries such as GMP and Python's integer arithmetic switch to Karatsuba once numbers reach a few dozen machine words, because RSA cryptography and high-precision computation multiply huge integers constantly.
Common Mistakes
Mistake: Using directly as the middle coefficient, which gives instead of in the example.
Correction: The product expands to . You must subtract both and to isolate . Also shift by and before adding, not by for both terms.
