1 / 19

CSE 421 Algorithms

CSE 421 Algorithms. Richard Anderson Lecture 15 Fast Fourier Transform. 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. Complex Analysis.

Télécharger la présentation

CSE 421 Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 421Algorithms 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: reqi • eqi = cos q + i sin q • a is an nth root of unity if an = 1 • Square roots of unity: +1, -1 • Fourth roots of unity: +1, -1, i, -i • Eighth roots of unity: +1, -1, i, -i, b + ib, b - ib, -b + ib, -b - ib where b = sqrt(2)

  4. e2pki/n • e2pi = 1 • epi = -1 • nth roots of unity: e2pki/n for k = 0 …n-1 • Notation: wk,n = e2pki/n • Interesting fact: 1 + wk,n + w2k,n + w3k,n + . . . + wn-1k,n = 0 for k != 0

  5. FFT Overview • Polynomial interpolation • Given n+1 points (xi,yi), there is a unique polynomial P of degree at most n which satisfies P(xi) = yi

  6. Polynomial Multiplication n-1 degree polynomials A(x) = a0 + a1x + a2x2 + … +an-1xn-1, B(x) = b0 + b1x + b2x2 + …+ bn-1xn-1 C(x) = A(x)B(x) C(x)=c0+c1x + c2x2 + … + c2n-2x2n-2 p1, p2, . . ., p2n A(p1), A(p2), . . ., A(p2n) B(p1), B(p2), . . ., B(p2n) C(p1), C(p2), . . ., C(p2n) C(pi) = A(pi)B(pi)

  7. FFT • Polynomial A(x) = a0 + a1x + . . . + an-1xn-1 • Compute A(wj,n) for j = 0, . . ., n-1 • For simplicity, n is a power of 2

  8. Useful trick A(x) = a0 + a1x + a2x2 + a3x3 +. . . + an-1xn-1 Aeven(x) = a0 + a2x + a4x2 + . . . + an-2x(n-2)/2 Aodd(x) = a1+ a3x + a5x2 + …+ an-1x(n-2)/2 Show: A(x) = Aeven(x2) + x Aodd(x2)

  9. Lemma: w2j,2n = wj,n Squares of 2nth roots of unity are nth roots of unity wj,2n = e2pji/2n The detail of j >= n is being ignored – don’t mention unless it comes up.

  10. FFT Algorithm // Evaluate the 2n-1th degree polynomial A at // w0,2n, w1,2n, w2,2n, . . ., w2n-1,2n FFT(A, 2n) Recursively compute FFT(Aeven, n) Recursively compute FFT(Aodd, n) for j = 0 to 2n-1 A(wj,2n) = Aeven(w2j,2n) + wj,2nAodd(w2j,2n)

  11. Polynomial Multiplication • n-1th degree polynomials A and B • Evaluate A and B at w0,2n, w1,2n, . . ., w2n-1,2n • Compute C(wj,2n) for j = 0 to 2n -1 • We know the value of a 2n-2th degree polynomial at 2n points – this determines a unique polynomial, we just need to determine the coefficients

  12. Now the magic happens . . . C(x) = c0 + c1x + c2x2 + … + c2n-1x2n-1 (we want to compute the ci’s) Let dj = C(wj,2n) D(x) = d0 + d1x + d2x2 + … + d2n-1x2n-1 Evaluate D(x) at the 2nth roots of unity D(wj,2n) = [see text for details] = 2nc2n-j

  13. Polynomial Interpolation • Build polynomial from the values of C at the 2nth roots of unity • Evaluate this polynomial at the 2nth roots of unity

  14. Dynamic Programming • Weighted Interval Scheduling • Given a collection of intervals I1,…,In with weights w1,…,wn, choose a maximum weight set of non-overlapping intervals Sorted by finish times 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 I1, I2, . . ., Ij Opt[ j ] = max( Opt[ j – 1], wj + Opt[ p [ j ] ])

  17. Algorithm MaxValue(j) = if j = 0 return 0 else return max( MaxValue(j-1), wj + 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),wj + MaxValue(p[ j ])); return M[ j ];

More Related