Вы находитесь на странице: 1из 2

Sean Li

CS 4820 Notes Spring 2013


Introduction to Algorithms
Lecture 12 2/15/13
Prelim 1. Next Thursday night, 2/21/13, 7:30 pm, Uris auditorium.
Polynomial Multiplication Let f, g C[x]. Suppose f =

n1
i=0
a
i
x
i
and g =

n1
i=0
b
i
x
i
.
We denote the convolution of f and g as f g = (a
0
b
0
, a
1
b
0
+ a
0
b
1
, . . . , a
n
, b
n1
. Like in
integer multiplication, split f into f
0
and f
1
x
n
2
. Then
fg = (f
0
+ f
1
x
n
2
)(g
0
+ g
1
x
n
2
) = f
0
g
0
+ (f
1
g
0
+ f
0
g
1
)x
n
2
+ f
1
g
1
x
n
.
Can be improved by computing only 3 products by f
0
g
0
, f
1
g
1
, and (f
0
+ f
1
)(g
0
+ g
1
). This
gives T(n) = O(n
log
2
3
) = O(n
1.59...
).
There is an even faster way. Pick n data points
i
and represent the polynomials f and
g by their values on data points. This allows us to multiply numbers instead of taking a
convolution, as (fg)(
i
) = f(
i
)g(
i
).
Polynomial multiplication can be done with a matrix by a Vandermonde matrix.
_

_
1 a
1
a
n1
1
1 a
2
a
n1
2
.
.
.
.
.
.
.
.
.
.
.
.
1 a
n
a
n1
n
_

_
_
_
_
_
_

2
.
.
.

n
_
_
_
_
_
=
_
_
_
_
_
f(
1
)
f(
2
)
.
.
.
f(
n
)
_
_
_
_
_
Fast Fourier Transform. Can be done quickly by picking the n data points as the n-th
roots of unity, denote the group C
n
= {1, , . . . ,
n1
} where = e
2i
n
. In fact, since C is
algebraically closed, every polynomial in C factors completely into linear factors.
Let F
n
be the Vandermonde matrix with C
n
as the elements of the rows.
_

_
1 1 1
1
n1
.
.
.
.
.
.
.
.
.
.
.
.
1
n1

_

_
= (
ij
).
Then
F
1
n
=
1
n
(
ij
).
Proof.
F
n
F
1
n
=
1
n
n1

(ij)k
=
_
1
n

n1
i=0
1 = 1 if i = j
0 if i = j
as the sum of elements of the roots of unity is 0.
With
n
= 1, we can take (
2
)
n
2
= 1. This divide and conquer gives T(n) = 2T
_
n
2
_
+O(n) =
O(nlog n).
Write f(x) =

n1
i=0
a
i
x
i
= f
0
(x
2
) + xf
1
(x
2
) where
f
0
(x) = a
0
+ a
2
x + a
4
x
2
+ + a
n2
x
n
2
1
,
f
1
(x) = a
1
+ a
3
x + a
5
x
2
+ + a
n1
x
n
2
1
.
Use the relation
F
n
(f) = F
n
(f
0
(x
2
) + xf
1
(x
2
)) = F
n
(f
0
(x
2
)) + F
n
(x)F
n
(f
1
(x
2
)).
But
F
n
(f
0
(x
2
)) = (f
0
(1), f
0
(
2
), f
0

4
, . . . ) = F
n
2
(f
0
(x)) F
n
2
(f
0
(x))
where denotes concatenation. So,
F
n
(f) =
_
F
n
2
(f
0
(x)) F
n
2
(f
0
(x))
_
+ (1, , . . . ,
n1
)
_
F
n
2
(f
1
(x)) F
n
2
(f
1
(x))
_
.
The order is thus O(nlog n).
Page 2

Вам также может понравиться