Integer Multiplication Flashcards

1
Q

Different Integer Multiplication Algorithms

A

Regular

Divide Conquer

Karatsuba Algo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Regular Algorithm For Integer Multiplication Input

A

Input will be two numbers in the form of an array each value corresponding to its 10th power, the Same as output

This reduces operations by multiplying by single digits and shifting resulting in the possibility of around n operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Time Complexity and Space Complexity of Regular Algorithm For Integer Mul

A

Time Complex ; Theta(n^2)
Space; Theta(n)

For a long time, scientists thought it was the fastest.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Regular Algorithm For Integer Multiplication : General

A

Grade School Multiplication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Divide Conquer Integer Multiplication Input

A

Input: X, Y, n

Let X,Y be n-digit numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Divide Conquer Integer Multiplication Time Complexity

A

Omega(n^2)

Not any better than the regular algorithm, but it is the intermediate between the fastest, Karatsuba where we use a portion of this algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Divide Conquer Integer Multiplication Algorithm

A

Function SplitMul(x, y, n)
1: if n = 1 then
2: return x · y
3: else
4: m ← ⌈n/2⌉
5: a ← ⌊x/10m⌋; b ← x mod 10m
7: c ← ⌊y/10m⌋; d ← y mod 10m
8: e ← SplitMul(a, c, m)
9: f ← SplitMul(b, d, m)
10: g ← SplitMul(b, c, m)
11: h ← SplitMul(a, d, m)
12: return 10^(2m) e + 10^m *(g + h) + f

REASON:
■ Denote m = ⌈n/2⌉,
■ Let x = (10^m · a + b) and y = (10^m · c + d),
■ Then, xy = 10^(2m)ac + 10^m(bc + ad) + bd.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Karatsuba Algorithm Input

A

Input: X, Y, n

Let X,Y be n-digit numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Karatsuba Time Complexity

A

FASTEST:
O(n^1.58)

T(n) = 3T(⌈n/2⌉) + Θ(n)
Because 1 less recursion call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Karatsuba Algorithm

A

From Divide and Conquer we know we need xy = 10^(2m)ac + 10^m(bc + ad) + bd. To get bc + ad we do ac+bd −(a−b)(c−d) = bc+ad.
HERE IS ALGO:

Function FastMul(x, y, n)
1: if n = 1 then
2: return x · y
3: else
4: m ← ⌈n/2⌉
5: a ← ⌊x/10m⌋; b ← x mod 10m
7: c ← ⌊y/10m⌋; d ← y mod 10m
8: e ← SplitMul(a, c, m)
9: f ← SplitMul(b, d, m)
10: g ← SplitMul(a-b, c-d, m)
12: return 10^(2m) e + 10^m *(e+f-g) + f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly