I
I
Isaac Clark2015-01-29 22:06:04
Algorithms
Isaac Clark, 2015-01-29 22:06:04

Who can explain the Karatsuba Multiplication Algorithm?

Hello, tell me please.
I'm analyzing the Karatsuba multiplication algorithm and ran into a problem that I can't understand how step5 works correctly .
That is, we took step1 and added four zeros to it, why?
Because we have four digits in step2 ?
Why did we add two zeros in step4 ?
Please explain "on your fingers" how to work with this formula correctly and how to get step5 correctly , or rather, how and where these zeros come from.
Thanks for your help and your time.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sumor, 2015-01-29
@Dark_Knight

ab × cd
According to the formula we get:

(a × c) × 1000   +   b × d   +   ( (a + b) × (c + d) - a × c - b × d ) × 100 =
= 1000 × a × c + b × d  + ( a × c + a × d + b × c + b × d - a × c - b × d ) × 100 =
= 1000 × a × c + b × d  + ( a × d + b × c )  × 100 =
= 1000 × a × c + 100 × a × d + 100 × b × c + b × d

In total, we got the classic multiplication by a column, only in the numeral system.
Only in classical multiplication we have four multiplications, and in the proposed algorithm there are only three.

S
Sergey, 2015-01-29
Protko @Fesor

On fingers. Suppose we have two integers of dimension n . Then

X = 10^(n/2) * a + b;
Y = 10^(n/2) * c + d;

Multiply:
Or if we simplify
Or if we add variables:
s1 = ac; // step 1
s2 = bd; // step 2
s3 = ad + bc; //step 3
X * Y = 10^n * s1 + 10^(n/2) * s3 + s2;

In fact, the fifth step is just this formula.
The whole point is that when we calculate s1 or s2 or s3 we are again dealing with multiplication and we can apply the same algorithm, recursively reducing the dimension of the operands, thereby reducing the number of necessary operations.
@updated: fixed typos.

A
Anton Menshov, 2015-01-29
@Anton_Menshov

In addition to the above explanations, I will add: at first it was easier for me to deal with fast matrix multiplication (Strassen multiplication, https://ru.wikipedia.org/wiki/Strassen_Algorithm). This is one of the most visual (in the mathematical sense) fast divide-and-conquer algorithms. It's easier for me to think in terms of matrices than the constituent parts of numbers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question