Oct. 2 Oct. 4 - QUIZ #2
Oct. 2 Oct. 4 - QUIZ #2
Oct. 2 Oct. 4 - QUIZ #2
Oct. 2
Oct. 4 – QUIZ #2
polynomial of degree d
p(x) = a0 + a1 x + ... + ad xd
Representing polynomial of degree d
evaluation interpolation
polynomial of degree d
p(x) = a0 + a1 x + ... + ad xd
Evaluation
polynomial of degree d
p(x) = a0 + a1 x + ... + ad xd
(Horner’s rule)
a0+x(a1+x(a2 + ... )))
R0
for i from d to 0 do R R*x + ai
Interpolation
a polynomial p of degree d such that
p(a0) = 1
p(a1) = 0 (x-a 1 )(x-a 2 )...(x-a d )
.... (a0-a1)(a0-a2)...(a0-ad)
p(ad) = 0
p1 = (1/2) x2 – (1/2) x
p 2 = - x2 +1
p3 = (1/2) x2 + (1/2) x
Interpolation
1) compute p = (x-a0)...(x-ad)
2) compute
pi = p / (x-ai) for i=0,...,d
ri = pi / pi(ai)
3) compute
q = c0 r0 + ... + cd rd
interpolation O(d2)
MAIN GOAL: Multiplying polynomials
Polynomial of degree d
p(x) = a0 + a1 x + ... + ad xd
Polynomial of degree d’
q(x) = b0 + b1 x + ... + bd’ xd’
multiply
in
O(d) time
interpolate pq in evaluation
pq representation
Evaluation on multiple points
1
x
x2
(a0,a1,a2,...,ad) .
.
xd
Evaluation of a polynomial
on multiple points
1 1 1
x1 x2 xn
x12 x22 x n2
(a0,a1,a2,...,ad) .
. . ...
. . .
x1d x2d x nd
Vandermonde matrix
Fourier transform
1 1 1
1 1 d-1
1 2 2(d-1)
(a0,a1,a2,...,ad) . . .
. . . . . .
2
1 d-1 (d-1)
1 1 1 1 1 1
1 1 d-1 1 -1 1-d
1 2 2(d-1) 1 -2 2(1-d)
. . . . . .
. ... . . . .
. 2 . . .
2
1 d-1 (d-1) 1 1-d -(d-1)
= e2 i / d
Fourier transform – matrix view
1
1
I D Fn 0 ...
1
I -D 1 ...
0 Fn
D=diag(1,,...,d-1)
d=2n
String matching
string = x1,....,xn
pattern = p1,...,pk
k
TEST = (xi – pi)2
i=1
Occurs on position j ?
String matching
string = x1,....,xn
pattern = p1,...,pk
k
TEST = (xi – pi)2
i=1
Occurs on position j ?
k
TESTj = (xi+j-1 – pi)2
i=1
String matching with “don’t cares”
Occurs on position j ?
k
TESTj = (xi+j-1 – pi)2
i=1
pj = 0 DON’T CARE
k
TESTj = pj(xi+j-1 – pi)2
i=1