0

I was trying to analyse karatsuba algorithm for multiplying an m and an n digit integer. As i understand, it will be most efficient if the integers are divided into m/2 and n/2 digit sub problems. The issues are as follows:-

  1. Can we apply gauss trick in this case and do we need some adjustments to apply it. Padding the smaller integer to match the size may be a solution but will it affect my running time.

  2. In karatsuba algorithm, application of gauss trick ie (a+b)*(c+d) requires T(n/2 +1) as the size of the subproblem may increase by 1 digit. Can i some which way limit the size of sub problem to strictly n/2.

anuag
  • 1
  • 1

1 Answers1

0

Actually, Karatsuba algo complexity, using Master method is T(n) = 3 * T(n / 2) + O(n),

where N is a maximum of number's length. Actually, even if size of one sub problem is bigger for 1 digit, we don't care. Since it's just small constant.

Also, I'm not sure, what Gauss trick you're talking about? Usually this is a trick where we split first number on two parts (a, b) and second number on parts (c, d).

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

So, we need to calculate ac, bd and ad + bc = (a + b) * (c + d) - ac - bd. So we need to calculate only 3 products of smaller size. And, yes - we could apply it in Karatsuba algorithm.

For more information - check this lecture from Standford Univercity (http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=IntroToAlgorithms&video=CS161L1P9)

Mysterion
  • 9,050
  • 3
  • 30
  • 52
  • Absolutely so in this, if we have m and n digits it becomes (10 ^ (n / 2) * a + b) * (10 ^ (m / 2) * c + d) = 10^n/2*10^m/2 * a * c + 10 ^ (n / 2) * a * d + 10 ^ (m / 2) * b * c + b * d; and now how do we represent ad+bc as (a+b)(c+d)-ac-bd as the 10's power is different – anuag Aug 09 '13 at 06:16