Download presentation
Presentation is loading. Please wait.
1
Administrative Oct. 2 Oct. 4 – QUIZ #2 (pages 45-79 of DPV)
2
Polynomials p(x) = a 0 + a 1 x +... + a d x d polynomial of degree d
3
Representing polynomial of degree d (d+1 coefficients) (evaluation on d+1 points) the coefficient representation the value representation evaluationinterpolation
4
Evaluation p(x) = a 0 + a 1 x +... + a d x d polynomial of degree d
5
Evaluation p(x) = a 0 + a 1 x +... + a d x d polynomial of degree d (Horner’s rule) a 0 +x(a 1 +x(a 2 +... ))) R 0 for i from d to 0 do R R*x + a i
6
Interpolation a polynomial p of degree d such that p(a 0 ) = 1 p(a 1 ) = 0.... p(a d ) = 0 (x-a 1 )(x-a 2 )...(x-a d ) (a 0 -a 1 )(a 0 -a 2 )...(a 0 -a d ) p 1 = (1/2) x 2 – (1/2) x p 2 = - x 2 + 1 p 3 = (1/2) x 2 + (1/2) x
7
Interpolation 1) compute p = (x-a 0 )...(x-a d ) 2) compute p i = p / (x-a i ) for i=0,...,d r i = p i / p i (a i ) 3) compute q = c 0 r 0 +... + c d r d Claim: q(a i ) = c i for i=0,...,d
8
Polynomials evaluation on 1 point O(d) evaluation on d points O(d 2 ) interpolation O(d 2 )
9
MAIN GOAL: Multiplying polynomials p(x) = a 0 + a 1 x +... + a d x d Polynomial of degree d q(x) = b 0 + b 1 x +... + b d’ x d’ Polynomial of degree d’ p(x)q(x) = (a 0 b 0 ) + (a 0 b 1 + a 1 b 0 ) x +.... + (a d b d’ ) x d+d’
10
p,q evaluate on >2d points p,q in evaluation representation multiply in O(d) time pq in evaluation representation pq interpolate
11
Evaluation on multiple points p(x) = 7 + x + 5x 2 + 3x 3 + 6x 4 + 2x 5 p(z) = 7 + z + 5z 2 + 3z 3 + 6z 4 + 2z 5 p(-z) = 7 – z + 5z 2 – 3z 3 + 6z 4 – 2z 5 p(x) = (7+5x 2 + 6x 4 ) + x(1+3x 2 + 2x 4 ) p( x) = p e (x 2 ) + x p o (x 2 ) p(-x) = p e (x 2 ) – x p o (x 2 )
12
Evaluation on multiple points p(x) = a 0 + a 1 x + a 2 x 2 +... + a d x d p(x) = p e (x 2 ) + x p o (x 2 ) p(-x) = p e (x 2 ) – x p o (x 2 ) To evaluate p(x) on -x 1,x 1,-x 2,x 2,...,-x n,x n we only evaluate p e (x) and p o (x) on x 1 2,...,x n 2
13
Evaluation on multiple points To evaluate p(x) on -x 1,x 1,-x 2,x 2,...,-x n,x n we only evaluate p e (x) and p o (x) on x 1 2,...,x n 2 To evaluate p e (x) on x 1 2,...,x n 2 we only evaluate p e (x) on ?
14
n-th roots of unity 2 ik/n e k n = 1 k. l = k+l 0 + 1 +... + n-1 = 0 FACT 1: FACT 2: FACT 3: FACT 4: k = - k+n/2
15
FFT (a 0,a 1,...,a n-1, ) (s 0,...,s n/2-1 )= FFT(a 0,a 2,...,a n-2, 2 ) (z 0,...,z n/2-1 ) = FFT(a 1,a 3,...,a n-1, 2 ) s 0 + z 0 s 1 + z 1 s 2 + 2 z 2.... s 0 – z 0 s 1 - z 1 s 2 - 2 z 2....
16
Evaluation of a polynomial viewed as vector mutiplication (a 0,a 1,a 2,...,a d ) 1xx2..xd1xx2..xd
17
Evaluation of a polynomial on multiple points (a 0,a 1,a 2,...,a d ) 1x1x12..x1d1x1x12..x1d 1x2x22..x2d1x2x22..x2d 1xnxn2..xnd1xnxn2..xnd... Vandermonde matrix
18
Fourier transform (a 0,a 1,a 2,...,a d ) 111..1111..1 1 1 2. d-1 1 d-1 2(d-1). (d-1)... FT - matrix = e 2 i / d 2
19
Inverse fourier transform = e 2 i / d 111..1111..1 1 1 2. d-1 1 d-1 2(d-1). (d-1)... 2 111..1111..1 1 -1 -2. 1-d 1 1-d 2(1-d). -(d-1)... 2
20
Fourier transform – matrix view 0 0 FnFn FnFn I I D -D 1 1 1 1... D=diag(1, ,..., d-1 ) d=2 n
21
String matching string = x 1,....,x n pattern = p 1,...,p k (x i – p i ) 2 i=1 k Occurs on position j ? TEST =
22
String matching string = x 1,....,x n pattern = p 1,...,p k (x i – p i ) 2 i=1 k (x i+j-1 – p i ) 2 i=1 k Occurs on position j ? TEST = TEST j =
23
String matching with “don’t cares” (x i+j-1 – p i ) 2 i=1 k Occurs on position j ? TEST j = p j = 0 DON’T CARE p j (x i+j-1 – p i ) 2 i=1 k TEST j =
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.