Download presentation
Presentation is loading. Please wait.
1
CSE 421 Algorithms Richard Anderson Lecture 15 Fast Fourier Transform
2
FFT, Convolution and Polynomial Multiplication FFT: O(n log n) algorithm –Evaluate a polynomial of degree n at n points in O(n log n) time Polynomial Multiplication: O(n log n) time
3
Complex Analysis Polar coordinates: re i e i = cos + i sin a is an n th root of unity if a n = 1 Square roots of unity: +1, -1 Fourth roots of unity: +1, -1, i, -i –Eighth roots of unity: +1, -1, i, -i, + i , - i , - + i , - - i where = sqrt(2)
4
e 2 ki/n e 2 i = 1 e i = -1 n th roots of unity: e 2 ki/n for k = 0 …n-1 Notation: k,n = e 2 ki/n Interesting fact: 1 + k,n + 2 k,n + 3 k,n +... + n-1 k,n = 0 for k != 0
5
FFT Overview Polynomial interpolation –Given n+1 points (x i,y i ), there is a unique polynomial P of degree at most n which satisfies P(x i ) = y i
6
Polynomial Multiplication n-1 degree polynomials A(x) = a 0 + a 1 x + a 2 x 2 + … +a n-1 x n-1, B(x) = b 0 + b 1 x + b 2 x 2 + …+ b n-1 x n-1 C(x) = A(x)B(x) C(x)=c 0 +c 1 x + c 2 x 2 + … + c 2n-2 x 2n-2 p 1, p 2,..., p 2n A(p 1 ), A(p 2 ),..., A(p 2n ) B(p 1 ), B(p 2 ),..., B(p 2n ) C(p i ) = A(p i )B(p i ) C(p 1 ), C(p 2 ),..., C(p 2n )
7
FFT Polynomial A(x) = a 0 + a 1 x +... + a n-1 x n-1 Compute A( j,n ) for j = 0,..., n-1 For simplicity, n is a power of 2
8
Useful trick A(x) = a 0 + a 1 x + a 2 x 2 + a 3 x 3 +... + a n-1 x n-1 A even (x) = a 0 + a 2 x + a 4 x 2 +... + a n-2 x (n-2)/2 A odd (x) = a 1 + a 3 x + a 5 x 2 + …+ a n-1 x (n-2)/2 Show: A(x) = A even (x 2 ) + x A odd (x 2 )
9
Lemma: 2 j,2n = j,n Squares of 2n th roots of unity are n th roots of unity
10
FFT Algorithm // Evaluate the 2n-1 th degree polynomial A at // 0,2n, 1,2n, 2,2n,..., 2n-1,2n FFT(A, 2n) Recursively compute FFT(A even, n) Recursively compute FFT(A odd, n) for j = 0 to 2n-1 A( j,2n ) = A even ( 2 j,2n ) + j,2n A odd ( 2 j,2n )
11
Polynomial Multiplication n-1 th degree polynomials A and B Evaluate A and B at 0,2n, 1,2n,..., 2n-1,2n Compute C( j,2n ) for j = 0 to 2n -1 We know the value of a 2n-2 th degree polynomial at 2n points – this determines a unique polynomial, we just need to determine the coefficients
12
Now the magic happens... C(x) = c 0 + c 1 x + c 2 x 2 + … + c 2n-1 x 2n-1 (we want to compute the c i ’s) Let d j = C( j,2n ) D(x) = d 0 + d 1 x + d 2 x 2 + … + d 2n-1 x 2n-1 Evaluate D(x) at the 2n th roots of unity D( j,2n ) = [see text for details] = 2nc 2n-j
13
Polynomial Interpolation Build polynomial from the values of C at the 2n th roots of unity Evaluate this polynomial at the 2n th roots of unity
14
Dynamic Programming Weighted Interval Scheduling Given a collection of intervals I 1,…,I n with weights w 1,…,w n, choose a maximum weight set of non-overlapping intervals 4 6 3 5 7 6
15
Recursive Algorithm Intervals sorted by finish time p[i] is the index of the last interval which finishes before i starts 1 2 3 4 5 6 7 8
16
Optimality Condition Opt[j] is the maximum weight independent set of intervals I 1, I 2,..., I j
17
Algorithm MaxValue(j) = if j = 0 return 0 else return max( MaxValue(j-1), w j + MaxValue(p[ j ]))
18
Run time What is the worst case run time of MaxValue Design a worst case input
19
A better algorithm M[ j ] initialized to -1 before the first recursive call for all j MaxValue(j) = if j = 0 return 0; else if M[ j ] != -1 return M[ j ]; else M[ j ] = max(MaxValue(j-1),w j + MaxValue(p[ j ])); return M[ j ];
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.