DIVIDE AND CONQUER II

Size: px
Start display at page:

Download "DIVIDE AND CONQUER II"

Transcription

1 DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT Lecture slides by Kevin Wayne Copyright 005 Pearson-Addison Wesley SECTIONS Last updated on 11/3/17 5:53 AM Master method Goal. Recipe for solving common divide-and-conquer recurrences: with T0) = 0 and T1) = Θ1). T n) =at n + fn) b Geometric series Fact 1. For r 1, Fact. For r = 1, 1+r + r + r r k 1 = 1 rk 1 r 1+r + r + r r k 1 = k Fact 3. For r < 1, 1+r + r + r = 1 1 r Terms. a 1 is the integer) number of subproblems. b is the integer) factor by which the subproblem size decreases. f n) = work to divide and combine subproblems. 1/ Recursion tree. k = logb n levels. a i = number of subproblems at level i. n / b i = size of subproblem at level i. 1 1/4 1/16 1/8 1/ / +1/4 + 1/8 + = 3 4

2 Case 1: total cost dominated by cost of leaves Case : total cost evenly distributed among levels Ex 1. If T n) satisfies T n) = 3 T n / ) + n, with T 1) = 1, then T n) = n log 3 ). Ex. If T n) satisfies T n) = T n / ) + n, with T 1) = 1, then T n) = Θn log n). T n) n T n) n T n / ) T n / ) n / ) T n / ) T n / ) T n / ) 3 n / ) T n / 4) T n / 4) T n / 4) T n / 4) n / ) T n / 4) T n / 4) T n / 4) T n / 4) T n / 4) T n / 4) T n / 4) T n / 4) T n / 4) 3 n / ) log n log n 3 i n / i ) T n / 8) T n / 8) T n / 8) T n / 8) T n / 8) T n / 8) T n / 8) T n / 8) 3 n / 3 ) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1)... T 1) T 1) T 1) r = 3 / > 1 3 log n = n log 3 T n) =1+r + r + r r log n ) n = r 1+log n 1 r 1 n = 3n log 3 3 log n n/ log n ) n 5 T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1)... T 1) T 1) T 1) n 1) r = 1 log n = n T n) =1+r + r + r r log n ) n = n log n + 1) 6 Case 3: total cost dominated by cost of root Master theorem Ex 3. If T n) satisfies T n) = 3 T n / 4) + n 5, with T 1) = 1, then T n) = Θn 5 ). T n) T n / 4) T n / 4) T n / 4) T n / 16) T n / 16) T n / 16) T n / 16) T n / 16) T n / 16) T n / 16) T n / 16) T n / 16) log 4 n n 5 3 n / 4) 5 3 n / 4 ) 5 3 i n / 4 i ) 5 T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1) T 1)... log T 1) T 1) T 1) 3 n 4 n/4 log 4 n ) 5 3 log 4 n = n log 4 3 Master theorem. Suppose that T n) is a function on the non-negative integers that satisfies the recurrence T n) =at with T0) = 0 and T1) = Θ1), where n / b means either n / b or n / b. Then, Case 1. If f n) = On k ) for some constant k < log b a, then T n) = Θn log b a). Ex. T n) = 3 Tn / ) + 5 n. a = 3, b =, f n) = 5 n, k = 1, logb a = 1.58 T n) = n log 3 ). n b + fn) r = 3 / 4 5 < 1 n 5 T n) 1 + r + r + r 3 + ) n r n 5 7 8

3 Master theorem Master theorem Master theorem. Suppose that T n) is a function on the non-negative integers that satisfies the recurrence T n) =at with T0) = 0 and T1) = Θ1), where n / b means either n / b or n / b. Then, Case. If f n) = Θn k log p n) for p 0 and k = log b a, then T n) = Θn k log p+1 n). Ex. T n) = Tn / ) + 17 n log n. a =, b =, f n) = 17 n log n, k = 1, p = 1, log b a = 1. T n) = Θn log n). n b + fn) Master theorem. Suppose that T n) is a function on the non-negative integers that satisfies the recurrence T n) =at with T0) = 0 and T1) = Θ1), where n / b means either n / b or n / b. Then, Case 3. If f n) = Ωn k ) for some constant k > log b a, and if a f n / b) c f n) for some constant c < 1 and all sufficiently large n, then T n) = Θ f n)). Ex. T n) = 3 Tn / ) + n. a = 3, b =, f n) = n, k =, log b a = 1.58 Regularity condition: 3 n / ) c n for c = 3/4. T n) = Θn ). n b + fn) regularity condition holds if fn) = Θn k ) 9 10 Master theorem Master theorem need not apply Master theorem. Suppose that T n) is a function on the non-negative integers that satisfies the recurrence T n) =at n b + fn) Gaps in master theorem. Number of subproblems must be a constant. T n) = ntn/) + n with T0) = 0 and T1) = Θ1), where n / b means either n / b or n / b. Then, Case 1. If f n) = On k ) for some constant k < log b a, then T n) = Θn log b a). Case. If f n) = Θn k log p n) for p 0 and k = log b a, then T n) = Θn k log p+1 n). Number of subproblems must be 1. T n) = 1 T n/) + n Non-polynomial separation between fn) and n log b a. T n) = T n/) + n log n Case 3. If f n) = Ωn k ) for some constant k > logb a, and if a f n / b) c f n) for some constant c < 1 and all sufficiently large n, then T n) = Θ f n)). fn) is not positive. T n) = T n/) n Pf sketch. Use recursion tree to sum up terms assuming n is an exact power of b). Three cases for geometric series. Deal with floors and ceilings. 11 Regularity condition does not hold. T n) = T n/) + n cos n) 1

4 Akra Bazzi theorem Desiderata. Generalizes master theorem to divide-and-conquer algorithms where subproblems have substantially different sizes. Theorem. [Akra Bazzi] Given constants a i > 0 and 0 < b i 1, functions h i n) = On / log n) and gn) = On c ), if the function Tn) satisfies the recurrence: k T n) = a i T b i n + h i n)) + gn) n i=1 Then Tn) = n p gu) 1+ du where p satisfies a i b p i =1. up+1 1 ai subproblems of size bi n small perturbation to handle floors and ceilings Ex. Tn) = 7/4 T n / ) + T 3/4 n ) + n, with T0) = 0 and T1) = 1. a 1 = 7/4, b 1 = 1/, a = 1, b = 3/4 p =. h 1n) = 1/ n 1/ n, h n) = 3/4 n 3/4 n. gn) = n Tn) = Θn log n). k i=1 13 DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT Integer addition Integer multiplication Addition. Given two n-bit integers a and b, compute a + b. Subtraction. Given two n-bit integers a and b, compute a b. Multiplication. Given two n-bit integers a and b, compute a b. Grade-school algorithm. Θn ) bit operations. Grade-school algorithm. Θn) bit operations Remark. Grade-school addition and subtraction algorithms are asymptotically optimal. 15 Conjecture. [Kolmogorov 195] Grade-school algorithm is optimal. Theorem. [Karatsuba 1960] Conjecture is wrong. 16

5 Divide-and-conquer multiplication To multiply two n-bit integers x and y: Divide x and y into low- and high-order bits. Multiply four ½n-bit integers, recursively. Add and shift to obtain result. m = n / a = x / m b = x mod m c = y / m d = y mod m m a + b) m c + d) = m ac + m bc + ad) + bd Ex. x = y = a b c d 1 use bit shifting to compute 4 terms 3 4 Divide-and-conquer multiplication MULTIPLY x, y, n) IF n = 1) RETURN x y. ELSE m n /. a x / m ; b x mod m. c y / m ; d y mod m. e MULTIPLY a, c, m). f MULTIPLY b, d, m). g MULTIPLY b, c, m). h MULTIPLY a, d, m). RETURN m e + m g + h) + f Divide-and-conquer multiplication analysis Karatsuba trick Proposition. The divide-and-conquer multiplication algorithm requires Θn ) bit operations to multiply two n-bit integers. Pf. Apply case 1 of the master theorem to the recurrence: ) Tn) = 4T n/! " +! Θn) " Tn) = Θn ) recursive calls add, shift To compute middle term bc + ad, use identity: bc + ad = ac + bd a b) c d) m = n / a = x / m c = y / m b = x mod m d = y mod m middle term m a + b) m c + d) = m ac + m bc + ad ) + bd = m ac + m ac + bd a b)c d)) + bd Bottom line. Only three multiplications of n / -bit integers. 19 0

6 Karatsuba multiplication Karatsuba analysis KARATSUBA-MULTIPLY x, y, n) IF n = 1) RETURN x y. ELSE m n /. a x / m ; b x mod m. c y / m ; d y mod m. e KARATSUBA-MULTIPLY a, c, m). f KARATSUBA-MULTIPLY b, d, m). g KARATSUBA-MULTIPLY a b, c d, m). RETURN m e + m e + f g) + f. Proposition. Karatsuba s algorithm requires On ) bit operations to multiply two n-bit integers. Pf. Apply Case 1 of the master theorem to the recurrence: T n) = 3T n/) + n) = T n) = n log 3 ) = On ) Practice. Faster than grade-school algorithm for about bits. 1 Integer arithmetic reductions History of asymptotic complexity of integer multiplication Integer multiplication. Given two n-bit integers, compute their product. year algorithm order of growth? brute force Θn ) problem arithmetic running time integer multiplication a b Mn) integer division a / b, a mod b ΘMn)) integer square a ΘMn)) integer square root a ΘMn)) integer arithmetic problems with the same complexity Mn) as integer multiplication 196 Karatsuba Ofman Θn ) 1963 Toom-3, Toom-4 Θn ), Θn ) 1966 Toom Cook Θn 1 + ε ) 1971 Schönhage Strassen Θn log n log log n) 007 Fürer n log n Olog*n)?? Θn) number of bit operations to multiply two n-bit integers used in Maple, Mathematica, gcc, cryptography,... Remark. GNU Multiple Precision Library uses one of five different algorithms depending on size of operands. 3 4

7 Dot product SECTION 4. DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT Dot product. Given two length-n vectors a and b, compute c = a b. Grade-school. Θn) arithmetic operations. [ ] [ ] a = b = a b =.70.30) ) ) =.3 Remark. Grade-school dot product algorithm is asymptotically optimal. n a b = a i b i i=1 6 Matrix multiplication Block matrix multiplication Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. Grade-school. Θn 3 ) arithmetic operations. " c 11 c 1! c 1n c 1 c! c n = " " " c n1 c n! c nn " = " a 11 a 1! a 1n a 1 a! a n " " " a n1 a n! a nn " " " b 11 b 1! b 1n b 1 b! b n " " " b n1 b n! b nn c ij = Q. Is grade-school matrix multiplication algorithm asymptotically optimal? n k=1 a ik b kj A C 11 A 1 B " " " = C 11 = A 11 B 11 + A 1 B 1 = B =

8 Block matrix multiplication: warmup Strassen s trick To multiply two n-by-n matrices A and B: Divide: partition A and B into ½n-by-½n blocks. Conquer: multiply 8 pairs of ½n-by-½n matrices, recursively. Combine: add appropriate products using 4 matrix additions. C = A n-by-n matrices " C 11 C 1 " = A 11 A 1 " B 11 B 1 C 1 C A 1 A B 1 B B ½n-by-½n matrices Running time. Apply case 1 of the master theorem. ) + A 1 B 1 ) ) + A 1 B ) ) + A B 1 ) ) + A B ) C 11 = A 11 B 11 C 1 = A 11 B 1 C 1 = A 1 B 11 C = A 1 B 1 8 matrix multiplications of ½n-by-½n matrices) 4 matrix additions of ½n-by-½n matrices) Key idea. Can multiply two -by- matrices via 7 scalar multiplications plus 11 additions and 7 subtractions). " C 11 C 1 " = A 11 A 1 " B 11 B 1 P 1 A 11 B 1 B ) C 1 C A 1 A B 1 B P A 11 + A 1) B P 3 A 1 + A ) B 11 P 4 A B 1 B 11) C 11 = P 5 + P 4 P + P 6 C P 5 A 11 + A ) B 11 1 = P 1 + P + B ) C 1 = P 3 + P 4 P 6 A 1 A ) B 1 + B ) C = P 1 + P 5 P 3 P 7 P 7 A 11 A 1) B 11 + B 1) Pf. C 1 = P 1 + P scalars 7 scalar multiplications ) Tn) = 8T n/! " + Θn )!" recursive calls add, form submatrices Tn) = Θn 3 ) 9 = A 11 B 1 B ) + A 11 + A 1) B = A 11 B 1 + A 1 B. 30 Strassen s trick Strassen s algorithm n-by-n ½n-by-½n matrix Key idea. Can multiply two -by- matrices via 7 scalar multiplications plus 11 additions and 7 subtractions). " C 11 C 1 " A = 11 A 1 " B 11 B 1 C 1 C A 1 A B 1 B Pf. C1 = P1 + P C 11 = P 5 + P 4 P + P 6 C1 = P1 + P C1 = P3 + P4 ½n-by-½n matrices C = P1 + P5 P3 P7 = A11 B1 B) + A11 + A1) B = A11 B1 + A1 B. P 1 A 11 B 1 B ) P A 11 + A 1) B P 3 A 1 + A ) B 11 P 4 A B 1 B 11) P5 A11 + A) B11 + B) P6 A1 A) B1 + B) P7 A11 A1) B11 + B1) 7 matrix multiplications of ½n-by-½n matrices) 31 assume n is a power of STRASSEN n, A, B) IF n = 1) RETURN A B. Partition A and B into ½n-by-½n blocks. P 1 STRASSEN n /, A 11, B 1 B )). P STRASSEN n /, A 11 + A 1), B ). P 3 STRASSEN n /, A 1 + A ), B 11). P 4 STRASSEN n /, A, B 1 B 11)). P 5 STRASSEN n /, A 11 + A ), B 11 + B )). P6 STRASSEN n /, A1 A), B1 + B)). P7 STRASSEN n /, A11 A1), B11 + B1)). C11 = P5 + P4 P + P6. C1 = P1 + P. C1 = P3 + P4. C = P1 + P5 P3 P7. RETURN C. keep track of indices of submatrices don t copy matrix entries) " C 11 C 1 " A = 11 A 1 " B 11 B 1 C 1 C A 1 A B 1 B 3

9 Analysis of Strassen s algorithm Theorem. Strassen s algorithm requires On.81 ) arithmetic operations to multiply two n-by-n matrices. Pf. Apply case 1 of the master theorem to the recurrence: ) Tn) = 7T n /! " + Θn ) Tn) = Θn!" log 7 ) = On.81 ) recursive calls add, subtract Q. What if n is not a power of? A. Could pad matrices with zeros. Strassen s algorithm: practice Implementation issues. Sparsity. Caching effects. Numerical stability. Odd matrix dimensions. Crossover to classical algorithm when n is small. Common misperception. Strassen s algorithm is only a theoretical curiosity. Apple reports 8x speedup on G4 Velocity Engine when n,048. Range of instances where it s useful is a subject of controversy = Linear algebra reductions Fast matrix multiplication: theory Matrix multiplication. Given two n-by-n matrices, compute their product. problem linear algebra order of growth matrix multiplication A B MMn) matrix inversion A 1 ΘMMn)) determinant A ΘMMn)) system of linear equations Ax = b ΘMMn)) LU decomposition A = L U ΘMMn)) least squares min Ax b ΘMMn)) numerical linear algebra problems with the same complexity MMn) as matrix multiplication Q. Multiply two -by- matrices with 7 scalar multiplications? A. Yes! [Strassen 1969] Q. Multiply two -by- matrices with 6 scalar multiplications? A. Impossible. [Hopcroft Kerr 1971] Q. Multiply two 3-by-3 matrices with 1 scalar multiplications? A. Unknown. Begun, the decimal wars have. [Pan, Bini et al., Schönhage, ] Two 0-by-0 matrices with 4,460 scalar multiplications. Two 48-by-48 matrices with 47,17 scalar multiplications. A year later. December January Θn log 7 ) = On.807 ) Θn log 6 ) = On.59 ) Θn log 3 1 ) = On.77 ) On.805 ) On.7801 ) On.7799 ) On ) On ) 35 36

10 History of asymptotic complexity of matrix multiplication year algorithm order of growth? brute force O n 3 ) 1969 Strassen O n.808 ) 1978 Pan O n.796 ) 1979 Bini O n.780 ) 1981 Schönhage O n.5 ) 198 Romani O n.517 ) DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT 198 Coppersmith Winograd O n.496 ) 1986 Strassen O n.479 ) 1989 Coppersmith Winograd O n.376 ) 010 Strother O n.3737 ) 011 Williams O n.377 )?? O n + ε ) number of floating-point operations to multiply two n-by-n matrices 37 Fourier analysis Euler s identity Fourier theorem. [Fourier, Dirichlet, Riemann] Any sufficiently smooth) periodic function can be expressed as the sum of a series of sinusoids. Euler s identity. e ix = cos x + i sin x. Sinusoids. Sum of sine and cosines = sum of complex exponentials. t yt) = N sin kt N = π k k=

11 Time domain vs. frequency domain Time domain vs. frequency domain Signal. [touch tone button 1] Time domain. Frequency domain. sound pressure yt) = 1 sinπ 697 t) + 1 sinπ 109 t) Signal. [recording, 819 samples per second] Magnitude of discrete Fourier transform. 0.5 amplitude Reference: Cleve Moler, Numerical Computing with MATLAB Reference: Cleve Moler, Numerical Computing with MATLAB 41 4 Fast Fourier transform Fast Fourier transform: applications FFT. Fast way to convert between time-domain and frequency-domain. Alternate viewpoint. Fast way to multiply and evaluate polynomials. If you speed up any nontrivial algorithm by a factor of a million or so the world will beat a path towards finding useful applications for it. Numerical Recipes we take this approach Applications. Optics, acoustics, quantum physics, telecommunications, radar, control systems, signal processing, speech recognition, data compression, image processing, seismology, mass spectrometry, Digital media. [DVD, JPEG, MP3, H.64] Medical diagnostics. [MRI, CT, PET scans, ultrasound] Numerical solutions to Poisson s equation. Integer and polynomial multiplication. Shor s quantum factoring algorithm. The FFT is one of the truly great computational developments of [the 0th] century. It has changed the face of science and engineering so much that it is not an exaggeration to say that life as we know it would be very different without the FFT. Charles van Loan 43 44

12 Fast Fourier transform: brief history Polynomials: coefficient representation Gauss 1805, 1866). Analyzed periodic motion of asteroid Ceres. Runge-König 194). Laid theoretical groundwork. Danielson-Lanczos 194). Efficient algorithm, x-ray crystallography. Cooley Tukey 1965). Monitoring nuclear tests in Soviet Union and tracking submarines. Rediscovered and popularized FFT. Polynomial. [coefficient representation] Ax) = a 0 + a 1 x + a x +!+ a x Bx) = b 0 + b 1 x + b x +!+ b x Add. On) arithmetic operations. Ax)+ Bx) = a 0 +b 0 )+a 1 +b 1 )x +!+ a +b )x Evaluate. On) using Horner s method. paper published only after IBM lawyers decided not to set precedent of patenting numerical algorithms conventional wisdom: nobody could make money selling software!) Importance not fully realized until advent of digital computers. 45 Ax) = a 0 +xa 1 + xa +!+ xa n + xa ))!)) Multiply convolve). On ) using brute force. Ax) Bx) = n c i x i, where c i = a j b i j i =0 j =0 i 46 A modest Ph.D. dissertation title Polynomials: point-value representation DEMONSTRATIO NOVA THEOREMATIS OMNEM FVNCTIONEM ALGEBRAICAM RATIONALEM INTEGRAM VNIVS VARIABILIS IN FACTORES REALES PRIMI VEL SECUNDI GRADVS RESOLVI POSSE AVCTORE CAROLO FRIDERICO GAVSS HELMSTADII APVD C. G. FLECKEISEN Fundamental theorem of algebra. A degree n polynomial with complex coefficients has exactly n complex roots. Corollary. A degree n 1 polynomial Ax) is uniquely specified by its evaluation at n distinct values of x 1. y Quaelibet aequatio algebraica determinata reduci potest ad formam x m +Ax m-1 +Bx m- + etc. +M=0, ita vt m sit numerus integer positiuus. Si partem primam huius aequationis per X denotamus, aequationique X=0 per plures valores inaequales ipsius x satisfieri supponimus, puta ponendo x=α, x=β, x=γ etc. functio X per productum e factoribus x-α, x-β, x-γ etc. diuisibilis erit. Vice versa, si productum e pluribus factoribus simplicibus x- α, x-β, x-γ etc. functionem X metitur: aequationi X=0 satisfiet, aequando ipsam x cuicunque quantitatum α, β, γ etc. Denique si X producto ex m factoribus talibus simplicibus aequalis est siue omnes diuersi sint, siue quidam ex ipsis identici): alii factores simplices praeter hos functionem X metiri non poterunt. y j = Ax j ) Quamobrem aequatio m ti gradus plures quam m radices habere nequit; simul vero patet, aequationem m ti gradus pauciores radices habere posse, etsi X in m factores simplices resolubilis sit: New proof of the theorem that every algebraic rational integral function in one variable can be resolved into real factors of the first or the second degree. 47 x j x 48

13 Polynomials: point-value representation Converting between two representations Polynomial. [point-value representation] Ax) : x 0, y 0 ),, x n-1, y ) Bx) : x 0, z 0 ),, x n-1, z ) Add. On) arithmetic operations. Ax)+ Bx) : x 0, y 0 + z 0 ),, x n-1, y + z ) Multiply convolve). On), but need n 1 points. Ax) Bx) : x 0, y 0 z 0 ),, x n-1, y z ) Evaluate. On ) using Lagrange s formula. x x j ) j k Ax) = y k k=0 x k x j ) j k 49 Tradeoff. Fast evaluation or fast multiplication. We want both! representation multiply evaluate coefficient On ) On) point-value On) On ) Goal. Efficient conversion between two representations all ops fast. a 0, a 1,..., a x n-1 0, y 0 ),, x, y ) coefficient representation point-value representation 50 Converting between two representations: brute force Converting between two representations: brute force Coefficient point-value. Given a polynomial a 0 + a 1 x a n 1 x n 1, evaluate it at n distinct points x 0,..., x n 1. y 0 y 1 y! y = 1 x 0 x 0 " x 0 1 x 1 x 1 " x 1 1 x x " x!!!! 1 x x " x Running time. On ) for matrix-vector multiply or n Horner s). a 0 a 1 a! a Point-value coefficient. Given n distinct points x 0,..., x n 1 and values y 0,..., y n 1, find unique polynomial a 0 + a 1 x a n 1 x n 1, that has given values at given points. y 0 y 1 y! y = 1 x 0 x 0 " x 0 1 x 1 x 1 " x 1 1 x x " x!!!! 1 x x " x Running time. On 3 ) for Gaussian elimination. a 0 a 1 a! a Vandermonde matrix is invertible iff xi distinct or On.377 ) via fast matrix multiplication 51 5

14 Divide-and-conquer Decimation in frequency. Break up polynomial into low and high powers. Ax) = a 0 + a 1 x + a x + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7. A low x) = a 0 + a 1 x + a x + a 3 x 3. A high x) = a 4 + a 5 x + a 6 x + a 7 x 3. Ax) = A low x) + x 4 A high x). Decimation in time. Break up polynomial into even and odd powers. Ax) = a 0 + a 1 x + a x + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7. A even x) = a 0 + a x + a 4 x + a 6 x 3. A odd x) = a 1 + a 3 x + a 5 x + a 7 x 3. Ax) = A evenx ) + x A odd x ). Coefficient to point-value representation: intuition Coefficient point-value. Given a polynomial a 0 + a 1 x a n 1 x n 1, evaluate it at n distinct points x 0,..., x n 1. Divide. Break up polynomial into even and odd powers. Ax) = a 0 + a 1 x + a x + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7. A even x) = a 0 + a x + a 4 x + a 6 x 3. A odd x) = a 1 + a 3 x + a 5 x + a 7 x 3. Ax) = A evenx ) + x A odd x ). A-x) = A even x ) x A odd x ). Intuition. Choose two points to be ±1. A 1) = A even 1) + 1 A odd 1). A-1) = A even1) 1 A odd 1). we get to choose which ones! Can evaluate polynomial of degree n at points by evaluating two polynomials of degree ½n at 1 point Coefficient to point-value representation: intuition Discrete Fourier transform Coefficient point-value. Given a polynomial a 0 + a 1 x a n 1 x n 1, evaluate it at n distinct points x 0,..., x n 1. Divide. Break up polynomial into even and odd powers. Ax) = a 0 + a 1 x + a x + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7. A evenx) = a 0 + a x + a 4 x + a 6 x 3. A odd x) = a 1 + a 3 x + a 5 x + a 7 x 3. Ax) = A evenx ) + x A odd x ). A-x) = A even x ) x A odd x ). Intuition. Choose four complex points to be ±1, ±i. A 1) = A even 1) + 1 A odd 1). A-1) = A even 1) 1 A odd 1). A i ) = A even -1) + i A odd -1). A -i ) = A even -1) i A odd -1). we get to choose which ones! Can evaluate polynomial of degree n at 4 points by evaluating two polynomials of degree ½n at point. Coefficient point-value. Given a polynomial a 0 + a 1 x a n 1 x n 1, evaluate it at n distinct points x 0,..., x n 1. Key idea. Choose x k = ω k where ω is principal n th root of unity. y 0 y 1 y y 3! y = DFT " 1 1 ω 1 ω ω 3 " ω 1 ω ω 4 ω 6 " ω ) 1 ω 3 ω 6 ω 9 " ω 3)!!!!! 1 ω ω ) ω 3) " ω )) Fourier matrix Fn a 0 a 1 a a 3! a 55 56

15 Roots of unity Fast Fourier transform Def. An n th root of unity is a complex number x such that x n = 1. Fact. The n th roots of unity are: ω 0, ω 1,, ω n 1 where ω = e π i / n. Pf. ω k ) n = e π i k / n ) n = e π i ) k = -1) k = 1. Fact. The ½n th roots of unity are: ν 0, ν 1,, ν n/ 1 where ν = ω = e 4π i / n. ω = ν 1 = i ω 3 ω 1 ω 4 = ν = -1 n = 8 ω 0 = ν 0 = 1 ω 5 ω 7 Goal. Evaluate a degree n 1 polynomial Ax) = a a n 1 x n 1 at its n th roots of unity: ω 0, ω 1,, ω n 1. Divide. Break up polynomial into even and odd powers. A even x) = a 0 + a x + a 4 x + + a n- x n/ 1. A odd x) = a 1 + a 3 x + a 5 x + + a n-1 x n/ 1. Ax) = A even x ) + x A odd x ). Conquer. Evaluate A even x) and A odd x) at the ½n th roots of unity: ν 0, ν 1,, ν n/ 1. ν k = ω k ) Combine. Aω k ) = A even ν k ) + ω k A odd ν k ), 0 k < n/ Aω k+ ½n ) = A even ν k ) ω k A odd ν k ), 0 k < n/ ω 6 = ν 3 = -i ν k = ω k + ½n ) ω k+ ½n = -ω k FFT: implementation FFT: summary Theorem. The FFT algorithm evaluates a degree n 1 polynomial at each of the n th roots of unity in On log n) steps and On) extra space. FFT n, a 0, a 1, a,, a n 1) Pf. Tn) = Tn /) + Θn) Tn) = Θn logn) assumes n is a power of IF n = 1) RETURN a 0. e 0, e 1,, e n/ 1) FFT n /, a 0, a, a 4,, a n ). d 0, d 1,, d n/ 1) FFT n /, a 1, a 3, a 5,, a n 1). FOR k = 0 TO n / 1. ω k e πik/n. yk ek + ω k dk. yk + n/ ek ω k dk. RETURN y0, y1, y,, yn 1). a 0, a 1,..., a n-1 coefficient representation On log n)??? x 0, y 0 ),, x, y ) point-value representation 59 60

16 FFT: recursion tree Inverse discrete Fourier transform a 0, a 1, a, a 3, a 4, a 5, a 6, a 7 Point-value coefficient. Given n distinct points x 0,..., x n 1 and values y 0,..., y n 1, find unique polynomial a 0 + a 1 x a n 1 x n 1, that has given values at given points. inverse perfect shuffle a 0, a, a 4, a 6 a 0, a 4 a, a 6 a 1, a 5 a 1, a 3, a 5, a 7 a 3, a 7 a 0 a 1 a a 3! a = " ω 1 ω ω 3 " ω 1 ω ω 4 ω 6 " ω ) 1 ω 3 ω 6 ω 9 " ω 3)!!!!! 1 ω ω ) ω 3) " ω )) y 0 y 1 y y 3! y a 0 a 4 a a 6 a 1 a 5 a 3 a Inverse DFT Fourier matrix inverse Fn) -1 bit-reversed order 61 6 Inverse discrete Fourier transform Inverse FFT: proof of correctness Claim. Inverse of Fourier matrix F n is given by following formula: G n ! 1 1 ω 1 ω ω 3! ω ) ) ) = 1 1 ω ω 4 ω 6! ω ) ) n 1 ω 3 ω 6 ω 9! ω 3) ) ) " " " " " ) 1 ω ) ω ) ω 3)! ω )) ) Fn / n is a unitary matrix Consequence. To compute inverse FFT, apply same algorithm but use ω 1 = e π i / n as principal n th root of unity and divide the result by n). Claim. F n and G n are inverses. Pf. F n G n ) k k " = 1 n Summation lemma. Let ω be a principal n th root of unity. Then ω k j j=0 ω k j ω j k " = 1 n j=0 = n if k 0 mod n 0 otherwise ω k k ") j j=0 = Pf. If k is a multiple of n then ω k = 1 series sums to n. Each n th root of unity ω k is a root of x n 1 = x 1) 1 + x + x x n-1 ). if ω k 1 we have: 1 + ω k + ω k) + + ω kn-1) = 0 series sums to 0. 1 if k = k " 0 otherwise summation lemma below) 63 64

17 Inverse FFT: implementation Inverse FFT: summary Note. Need to divide result by n. Theorem. The inverse FFT algorithm interpolates a degree n 1 polynomial given values at each of the n th roots of unity in On log n) steps. INVERSE-FFT n, y 0, y 1, y,, y n 1) assumes n is a power of IF n = 1) RETURN y 0. e 0, e 1,, e n/ 1) INVERSE-FFT n /, y 0, y, y 4,, y n ). d 0, d 1,, d n/ 1) INVERSE-FFT n /, y 1, y 3, y 5,, y n 1). FOR k = 0 TO n / 1. ω k e πik/n. switch roles of ai and yi a k e k + ω k d k ). a k + n/ e k ω k d k ). RETURN a 0, a 1, a,, a n 1). a 0, a 1,..., a n-1 coefficient representation On log n) FFT) On log n) inverse FFT) x 0, y 0 ),, x, y ) point-value representation Polynomial multiplication FFT in practice? Theorem. Can multiply two degree n 1 polynomials in On log n) steps. Pf. pad with 0s to make n a power of coefficient representation coefficient representation a 0, a 1,, a n-1 b 0, b 1,, b n-1 c 0, c 1,, c n- FFTs On log n) inverse FFT On log n) Aω 0 ),..., Aω ) Bω 0 ),..., Bω ) point-value multiplication On) Cω 0 ),..., Cω ) 67 68

18 FFT in practice Integer multiplication, redux Fastest Fourier transform in the West. [Frigo Johnson] Optimized C library. Features: DFT, DCT, real, complex, any size, any dimension. Won 1999 Wilkinson Prize for Numerical Software. Portable, competitive with vendor-tuned code. Implementation details. Core algorithm is nonrecursive version of Cooley Tukey. Instead of executing predetermined algorithm, it evaluates your hardware and uses a special-purpose compiler to generate an optimized algorithm catered to shape of the problem. Runs in On log n) time, even when n is prime. Multidimensional FFTs Integer multiplication. Given two n-bit integers a = a n 1 a 1 a 0 and b = b n 1 b 1 b 0, compute their product a b. Convolution algorithm. Form two polynomials. Note: a = A), b = B). Compute Cx) = Ax) Bx). Evaluate C) = a b. Running time: On log n) complex arithmetic operations. Theory. [Schönhage Strassen 1971] On log n log log n) bit operations. Theory. [Fürer 007] n log n Olog* n) bit operations. Practice. [GNU Multiple Precision Arithmetic Library] Ax) = a 0 + a 1 x + a x +!+ a x Bx) = b 0 +b 1 x +b x +!+ b x It uses brute force, Karatsuba, and FFT, depending on the size of n. 70

DIVIDE AND CONQUER II

DIVIDE AND CONQUER II DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT SECTION 5.6 Fourier analysis Fourier theorem. [Fourier, Dirichlet, Riemann] Any sufficiently smooth)

More information

DIVIDE AND CONQUER II

DIVIDE AND CONQUER II DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

DIVIDE AND CONQUER II

DIVIDE AND CONQUER II DIVIDE AND CONQUER II DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT master theorem integer multiplication matrix multiplication convolution and FFT

More information

How to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi.

How to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi. How to ultiply Slides by Kevin Wayne. Copyright 5 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials Complex ultiplication Complex multiplication. a + bi) c + di) = x + yi.

More information

5.6 Convolution and FFT

5.6 Convolution and FFT 5.6 Convolution and FFT Fast Fourier Transform: Applications Applications. Optics, acoustics, quantum physics, telecommunications, control systems, signal processing, speech recognition, data compression,

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 14 Divide and Conquer Fast Fourier Transform Sofya Raskhodnikova 10/7/2016 S. Raskhodnikova; based on slides by K. Wayne. 5.6 Convolution and FFT Fast Fourier Transform:

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 5 Divide and Conquer: Fast Fourier Transform Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication Matrix Multiplication Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. n c ij = a ik b kj k=1 c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn = a 11 a 12 a 1n

More information

Chapter 5. Divide and Conquer. CS 350 Winter 2018

Chapter 5. Divide and Conquer. CS 350 Winter 2018 Chapter 5 Divide and Conquer CS 350 Winter 2018 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall

More information

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve

More information

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution.

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution. Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer.! Break up problem into several parts.! Solve each part recursively.! Combine solutions to sub-problems into overall solution. Most common

More information

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common

More information

The Fast Fourier Transform. Andreas Klappenecker

The Fast Fourier Transform. Andreas Klappenecker The Fast Fourier Transform Andreas Klappenecker Motivation There are few algorithms that had more impact on modern society than the fast Fourier transform and its relatives. The applications of the fast

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

Kartsuba s Algorithm and Linear Time Selection

Kartsuba s Algorithm and Linear Time Selection CS 374: Algorithms & Models of Computation, Fall 2015 Kartsuba s Algorithm and Linear Time Selection Lecture 09 September 22, 2015 Chandra & Manoj (UIUC) CS374 1 Fall 2015 1 / 32 Part I Fast Multiplication

More information

FFT: Fast Polynomial Multiplications

FFT: Fast Polynomial Multiplications FFT: Fast Polynomial Multiplications Jie Wang University of Massachusetts Lowell Department of Computer Science J. Wang (UMass Lowell) FFT: Fast Polynomial Multiplications 1 / 20 Overview So far we have

More information

Fast Convolution; Strassen s Method

Fast Convolution; Strassen s Method Fast Convolution; Strassen s Method 1 Fast Convolution reduction to subquadratic time polynomial evaluation at complex roots of unity interpolation via evaluation at complex roots of unity 2 The Master

More information

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Divide and Conquer: Polynomial Multiplication Version of October 7, 2014 Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Outline Outline: Introduction The polynomial multiplication

More information

The Fast Fourier Transform: A Brief Overview. with Applications. Petros Kondylis. Petros Kondylis. December 4, 2014

The Fast Fourier Transform: A Brief Overview. with Applications. Petros Kondylis. Petros Kondylis. December 4, 2014 December 4, 2014 Timeline Researcher Date Length of Sequence Application CF Gauss 1805 Any Composite Integer Interpolation of orbits of celestial bodies F Carlini 1828 12 Harmonic Analysis of Barometric

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 //8 Fast Integer Division Too (!) Schönhage Strassen algorithm CS 8: Algorithm Design and Analysis Integer division. Given two n-bit (or less) integers s and t, compute quotient q = s / t and remainder

More information

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer What you really need to know about recurrences Work per level changes geometrically with the level Geometrically increasing (x > 1) The

More information

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication Integer multiplication Say we have 5 baskets with 8 apples in each How do we determine how many apples we have? Count them all? That would take

More information

CS 580: Algorithm Design and Analysis

CS 580: Algorithm Design and Analysis CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 208 Announcement: Homework 3 due February 5 th at :59PM Final Exam (Tentative): Thursday, May 3 @ 8AM (PHYS 203) Recap: Divide

More information

Algorithms 6.5 REDUCTIONS. designing algorithms establishing lower bounds classifying problems intractability

Algorithms 6.5 REDUCTIONS. designing algorithms establishing lower bounds classifying problems intractability 6.5 REDUCTIONS Algorithms F O U R T H E D I T I O N designing algorithms establishing lower bounds classifying problems intractability R O B E R T S E D G E W I C K K E V I N W A Y N E Algorithms, 4 th

More information

Divide and Conquer algorithms

Divide and Conquer algorithms Divide and Conquer algorithms Another general method for constructing algorithms is given by the Divide and Conquer strategy. We assume that we have a problem with input that can be split into parts in

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Lecture 6-8 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments

More information

Introduction to Algorithms

Introduction to Algorithms Lecture 1 Introduction to Algorithms 1.1 Overview The purpose of this lecture is to give a brief overview of the topic of Algorithms and the kind of thinking it involves: why we focus on the subjects that

More information

CSCI Honor seminar in algorithms Homework 2 Solution

CSCI Honor seminar in algorithms Homework 2 Solution CSCI 493.55 Honor seminar in algorithms Homework 2 Solution Saad Mneimneh Visiting Professor Hunter College of CUNY Problem 1: Rabin-Karp string matching Consider a binary string s of length n and another

More information

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem Chapter 2. Divide-and-conquer algorithms The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem. 2. Recursively

More information

Introduction to Algorithms 6.046J/18.401J/SMA5503

Introduction to Algorithms 6.046J/18.401J/SMA5503 Introduction to Algorithms 6.046J/8.40J/SMA5503 Lecture 3 Prof. Piotr Indyk The divide-and-conquer design paradigm. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving

More information

Integer multiplication with generalized Fermat primes

Integer multiplication with generalized Fermat primes Integer multiplication with generalized Fermat primes CARAMEL Team, LORIA, University of Lorraine Supervised by: Emmanuel Thomé and Jérémie Detrey Journées nationales du Calcul Formel 2015 (Cluny) November

More information

CSE 421 Algorithms: Divide and Conquer

CSE 421 Algorithms: Divide and Conquer CSE 42 Algorithms: Divide and Conquer Larry Ruzzo Thanks to Richard Anderson, Paul Beame, Kevin Wayne for some slides Outline: General Idea algorithm design paradigms: divide and conquer Review of Merge

More information

Divide and Conquer. Andreas Klappenecker

Divide and Conquer. Andreas Klappenecker Divide and Conquer Andreas Klappenecker The Divide and Conquer Paradigm The divide and conquer paradigm is important general technique for designing algorithms. In general, it follows the steps: - divide

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 5 FFT and Divide and Conquer Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / 56 Outline DFT: evaluate a polynomial

More information

Chapter 5 Divide and Conquer

Chapter 5 Divide and Conquer CMPT 705: Design and Analysis of Algorithms Spring 008 Chapter 5 Divide and Conquer Lecturer: Binay Bhattacharya Scribe: Chris Nell 5.1 Introduction Given a problem P with input size n, P (n), we define

More information

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide

More information

Compute the Fourier transform on the first register to get x {0,1} n x 0.

Compute the Fourier transform on the first register to get x {0,1} n x 0. CS 94 Recursive Fourier Sampling, Simon s Algorithm /5/009 Spring 009 Lecture 3 1 Review Recall that we can write any classical circuit x f(x) as a reversible circuit R f. We can view R f as a unitary

More information

Speedy Maths. David McQuillan

Speedy Maths. David McQuillan Speedy Maths David McQuillan Basic Arithmetic What one needs to be able to do Addition and Subtraction Multiplication and Division Comparison For a number of order 2 n n ~ 100 is general multi precision

More information

Fast reversion of formal power series

Fast reversion of formal power series Fast reversion of formal power series Fredrik Johansson LFANT, INRIA Bordeaux RAIM, 2016-06-29, Banyuls-sur-mer 1 / 30 Reversion of power series F = exp(x) 1 = x + x 2 2! + x 3 3! + x 4 G = log(1 + x)

More information

University of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers. Lecture 5

University of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers. Lecture 5 University of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers Numerical algorithms: Lecture 5 Today we ll cover algorithms for various numerical problems:

More information

Computational Methods CMSC/AMSC/MAPL 460

Computational Methods CMSC/AMSC/MAPL 460 Computational Methods CMSC/AMSC/MAPL 460 Fourier transform Balaji Vasan Srinivasan Dept of Computer Science Several slides from Prof Healy s course at UMD Last time: Fourier analysis F(t) = A 0 /2 + A

More information

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication )

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) CSE 548: Analysis of Algorithms Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2015 Coefficient Representation

More information

Fast Fourier Transform

Fast Fourier Transform Why Fourier Transform? Fast Fourier Transform Jordi Cortadella and Jordi Petit Department of Computer Science Polynomials: coefficient representation Divide & Conquer Dept. CS, UPC Polynomials: point-value

More information

Computer Vision, Convolutions, Complexity and Algebraic Geometry

Computer Vision, Convolutions, Complexity and Algebraic Geometry Computer Vision, Convolutions, Complexity and Algebraic Geometry D. V. Chudnovsky, G.V. Chudnovsky IMAS Polytechnic Institute of NYU 6 MetroTech Center Brooklyn, NY 11201 December 6, 2012 Fast Multiplication:

More information

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101 A design paradigm Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/17 112 Multiplying complex numbers (from Jeff Edmonds slides) INPUT: Two pairs of integers, (a,b),

More information

CS 4424 Matrix multiplication

CS 4424 Matrix multiplication CS 4424 Matrix multiplication 1 Reminder: matrix multiplication Matrix-matrix product. Starting from a 1,1 a 1,n A =.. and B = a n,1 a n,n b 1,1 b 1,n.., b n,1 b n,n we get AB by multiplying A by all columns

More information

Multiplying huge integers using Fourier transforms

Multiplying huge integers using Fourier transforms Fourier transforms October 25, 2007 820348901038490238478324 1739423249728934932894??? integers occurs in many fields of Computational Science: Cryptography Number theory... Traditional approaches to

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes ) CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11 In-Class Midterm ( 7:05 PM 8:20 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your

More information

Interpolation on the unit circle

Interpolation on the unit circle Lecture 2: The Fast Discrete Fourier Transform Interpolation on the unit circle So far, we have considered interpolation of functions at nodes on the real line. When we model periodic phenomena, it is

More information

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016 CS125 Lecture 4 Fall 2016 Divide and Conquer We have seen one general paradigm for finding algorithms: the greedy approach. We now consider another general paradigm, known as divide and conquer. We have

More information

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide n c: Solve the problem

More information

Algorithms and Data Structures Strassen s Algorithm. ADS (2017/18) Lecture 4 slide 1

Algorithms and Data Structures Strassen s Algorithm. ADS (2017/18) Lecture 4 slide 1 Algorithms and Data Structures Strassen s Algorithm ADS (2017/18) Lecture 4 slide 1 Tutorials Start in week (week 3) Tutorial allocations are linked from the course webpage http://www.inf.ed.ac.uk/teaching/courses/ads/

More information

Fast Polynomial Multiplication

Fast Polynomial Multiplication Fast Polynomial Multiplication Marc Moreno Maza CS 9652, October 4, 2017 Plan Primitive roots of unity The discrete Fourier transform Convolution of polynomials The fast Fourier transform Fast convolution

More information

Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion

Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion During the past week, we learnt about inductive reasoning, in which we broke down a problem of size n, into one

More information

Notes for Recitation 14

Notes for Recitation 14 6.04/18.06J Mathematics for Computer Science October 4, 006 Tom Leighton and Marten van Dijk Notes for Recitation 14 1 The Akra-Bazzi Theorem Theorem 1 (Akra-Bazzi, strong form). Suppose that: is defined

More information

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication

CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication CPSC 518 Introduction to Computer Algebra Asymptotically Fast Integer Multiplication 1 Introduction We have now seen that the Fast Fourier Transform can be applied to perform polynomial multiplication

More information

Integer multiplication and the truncated product problem

Integer multiplication and the truncated product problem Integer multiplication and the truncated product problem David Harvey Arithmetic Geometry, Number Theory, and Computation MIT, August 2018 University of New South Wales Political update from Australia

More information

1 Divide and Conquer (September 3)

1 Divide and Conquer (September 3) The control of a large force is the same principle as the control of a few men: it is merely a question of dividing up their numbers. Sun Zi, The Art of War (c. 400 C.E.), translated by Lionel Giles (1910)

More information

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

More information

CS S Lecture 5 January 29, 2019

CS S Lecture 5 January 29, 2019 CS 6363.005.19S Lecture 5 January 29, 2019 Main topics are #divide-and-conquer with #fast_fourier_transforms. Prelude Homework 1 is due Tuesday, February 5th. I hope you ve at least looked at it by now!

More information

Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d)

Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d) DS 2018/19 Lecture 4 slide 3 DS 2018/19 Lecture 4 slide 4 Tutorials lgorithms and Data Structures Strassen s lgorithm Start in week week 3 Tutorial allocations are linked from the course webpage http://www.inf.ed.ac.uk/teaching/courses/ads/

More information

The tangent FFT. D. J. Bernstein University of Illinois at Chicago

The tangent FFT. D. J. Bernstein University of Illinois at Chicago The tangent FFT D. J. Bernstein University of Illinois at Chicago Advertisement SPEED: Software Performance Enhancement for Encryption and Decryption A workshop on software speeds for secret-key cryptography

More information

1 Caveats of Parallel Algorithms

1 Caveats of Parallel Algorithms CME 323: Distriuted Algorithms and Optimization, Spring 2015 http://stanford.edu/ reza/dao. Instructor: Reza Zadeh, Matroid and Stanford. Lecture 1, 9/26/2015. Scried y Suhas Suresha, Pin Pin, Andreas

More information

2. ALGORITHM ANALYSIS

2. ALGORITHM ANALYSIS 2. ALGORITHM ANALYSIS computational tractability asymptotic order of growth survey of common running times Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Divide and conquer. Philip II of Macedon

Divide and conquer. Philip II of Macedon Divide and conquer Philip II of Macedon Divide and conquer 1) Divide your problem into subproblems 2) Solve the subproblems recursively, that is, run the same algorithm on the subproblems (when the subproblems

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 4: Divide and Conquer (I) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Divide and Conquer ( DQ ) First paradigm or framework DQ(S)

More information

Parallelism in Computer Arithmetic: A Historical Perspective

Parallelism in Computer Arithmetic: A Historical Perspective Parallelism in Computer Arithmetic: A Historical Perspective 21s 2s 199s 198s 197s 196s 195s Behrooz Parhami Aug. 218 Parallelism in Computer Arithmetic Slide 1 University of California, Santa Barbara

More information

The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d)

The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d) The Master Theorem for solving recurrences lgorithms and Data Structures Strassen s lgorithm 23rd September, 2014 Theorem Let n 0 N, k N 0 and a, b R with a > 0 and b > 1, and let T : N R satisfy the following

More information

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2 CMPSCI611: Three Divide-and-Conquer Examples Lecture 2 Last lecture we presented and analyzed Mergesort, a simple divide-and-conquer algorithm. We then stated and proved the Master Theorem, which gives

More information

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem CS 577 Introduction to Algorithms: Jin-Yi Cai University of Wisconsin Madison In the last class, we described InsertionSort and showed that its worst-case running time is Θ(n 2 ). Check Figure 2.2 for

More information

COMP 9024, Class notes, 11s2, Class 1

COMP 9024, Class notes, 11s2, Class 1 COMP 90, Class notes, 11s, Class 1 John Plaice Sun Jul 31 1::5 EST 011 In this course, you will need to know a bit of mathematics. We cover in today s lecture the basics. Some of this material is covered

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;

More information

shelat 16f-4800 sep Matrix Mult, Median, FFT

shelat 16f-4800 sep Matrix Mult, Median, FFT L5 shelat 16f-4800 sep 23 2016 Matrix Mult, Median, FFT merge-sort (A, p, r) if p

More information

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication The divide-and-conquer strategy solves a problem by: Chapter 2 Divide-and-conquer algorithms 1 Breaking it into subproblems that are themselves smaller instances of the same type of problem 2 Recursively

More information

Fast and Small: Multiplying Polynomials without Extra Space

Fast and Small: Multiplying Polynomials without Extra Space Fast and Small: Multiplying Polynomials without Extra Space Daniel S. Roche Symbolic Computation Group School of Computer Science University of Waterloo CECM Day SFU, Vancouver, 24 July 2009 Preliminaries

More information

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n Class Note #14 Date: 03/01/2006 [Overall Information] In this class, we studied an algorithm for integer multiplication, which improved the running time from θ(n 2 ) to θ(n 1.59 ). We then used some of

More information

Old and new algorithms for computing Bernoulli numbers

Old and new algorithms for computing Bernoulli numbers Old and new algorithms for computing Bernoulli numbers University of New South Wales 25th September 2012, University of Ballarat Bernoulli numbers Rational numbers B 0, B 1,... defined by: x e x 1 = n

More information

Scientific Computing: An Introductory Survey

Scientific Computing: An Introductory Survey Scientific Computing: An Introductory Survey Chapter 12 Prof. Michael T. Heath Department of Computer Science University of Illinois at Urbana-Champaign Copyright c 2002. Reproduction permitted for noncommercial,

More information

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points randomized quicksort median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Algorithm runtime analysis and computational tractability Time Complexity of an Algorithm How do we measure the complexity (time, space requirements) of an algorithm. 1 microsecond? Units of time As soon

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2015 Date: October 12. In-Class Midterm. ( 1:05 PM 2:20 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Fall 2015 Date: October 12. In-Class Midterm. ( 1:05 PM 2:20 PM : 75 Minutes ) CSE548, AMS542: Analysis of Algorithms, Fall 2015 Date: October 12 In-Class Midterm ( 1:05 PM 2:20 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your

More information

Sparse Fourier Transform (lecture 1)

Sparse Fourier Transform (lecture 1) 1 / 73 Sparse Fourier Transform (lecture 1) Michael Kapralov 1 1 IBM Watson EPFL St. Petersburg CS Club November 2015 2 / 73 Given x C n, compute the Discrete Fourier Transform (DFT) of x: x i = 1 x n

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Chapter 2 2.1 Computational Tractability Basics of Algorithm Analysis "For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious.

More information

Algorithms and data structures

Algorithms and data structures Algorithms and data structures Amin Coja-Oghlan LFCS Complex numbers Roots of polynomials A polynomial of degree d is a function of the form p(x) = d a i x i with a d 0. i=0 There are at most d numbers

More information

Chapter 2. Divide-and-conquer. 2.1 Strassen s algorithm

Chapter 2. Divide-and-conquer. 2.1 Strassen s algorithm Chapter 2 Divide-and-conquer This chapter revisits the divide-and-conquer paradigms and explains how to solve recurrences, in particular, with the use of the master theorem. We first illustrate the concept

More information

Divide and Conquer. Chapter Overview. 1.2 Divide and Conquer

Divide and Conquer. Chapter Overview. 1.2 Divide and Conquer Chapter 1 Divide and Conquer 1.1 Overview This chapter introduces Divide and Conquer, which is a technique for designing recursive algorithms that are (sometimes) asymptotically efficient. It also presents

More information

Chapter 4 Divide-and-Conquer

Chapter 4 Divide-and-Conquer Chapter 4 Divide-and-Conquer 1 About this lecture (1) Recall the divide-and-conquer paradigm, which we used for merge sort: Divide the problem into a number of subproblems that are smaller instances of

More information

arxiv: v1 [cs.na] 8 Feb 2016

arxiv: v1 [cs.na] 8 Feb 2016 Toom-Coo Multiplication: Some Theoretical and Practical Aspects arxiv:1602.02740v1 [cs.na] 8 Feb 2016 M.J. Kronenburg Abstract Toom-Coo multiprecision multiplication is a well-nown multiprecision multiplication

More information

Transforms and Orthogonal Bases

Transforms and Orthogonal Bases Orthogonal Bases Transforms and Orthogonal Bases We now turn back to linear algebra to understand transforms, which map signals between different domains Recall that signals can be interpreted as vectors

More information

Appendix C: Recapitulation of Numerical schemes

Appendix C: Recapitulation of Numerical schemes Appendix C: Recapitulation of Numerical schemes August 31, 2009) SUMMARY: Certain numerical schemes of general use are regrouped here in order to facilitate implementations of simple models C1 The tridiagonal

More information

Fast algorithms for polynomials and matrices Part 2: polynomial multiplication

Fast algorithms for polynomials and matrices Part 2: polynomial multiplication Fast algorithms for polynomials and matrices Part 2: polynomial multiplication by Grégoire Lecerf Computer Science Laboratory & CNRS École polytechnique 91128 Palaiseau Cedex France 1 Notation In this

More information

Reductions, Recursion and Divide and Conquer

Reductions, Recursion and Divide and Conquer Chapter 5 Reductions, Recursion and Divide and Conquer CS 473: Fundamental Algorithms, Fall 2011 September 13, 2011 5.1 Reductions and Recursion 5.1.0.1 Reduction Reducing problem A to problem B: (A) Algorithm

More information

Module 1: Analyzing the Efficiency of Algorithms

Module 1: Analyzing the Efficiency of Algorithms Module 1: Analyzing the Efficiency of Algorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu What is an Algorithm?

More information

feb abhi shelat Matrix, FFT

feb abhi shelat Matrix, FFT L7 feb 11 2016 abhi shelat Matrix, FFT userid: = Using the standard method, how many multiplications does it take to multiply two NxN matrices? cos( /4) = cos( /2) = sin( /4) = sin( /2) = Mergesort Karatsuba

More information

CPSC 518 Introduction to Computer Algebra Schönhage and Strassen s Algorithm for Integer Multiplication

CPSC 518 Introduction to Computer Algebra Schönhage and Strassen s Algorithm for Integer Multiplication CPSC 518 Introduction to Computer Algebra Schönhage and Strassen s Algorithm for Integer Multiplication March, 2006 1 Introduction We have now seen that the Fast Fourier Transform can be applied to perform

More information

CS168: The Modern Algorithmic Toolbox Lecture #11: The Fourier Transform and Convolution

CS168: The Modern Algorithmic Toolbox Lecture #11: The Fourier Transform and Convolution CS168: The Modern Algorithmic Toolbox Lecture #11: The Fourier Transform and Convolution Tim Roughgarden & Gregory Valiant May 8, 2015 1 Intro Thus far, we have seen a number of different approaches to

More information

Implementation of the DKSS Algorithm for Multiplication of Large Numbers

Implementation of the DKSS Algorithm for Multiplication of Large Numbers Implementation of the DKSS Algorithm for Multiplication of Large Numbers Christoph Lüders Universität Bonn The International Symposium on Symbolic and Algebraic Computation, July 6 9, 2015, Bath, United

More information

Three Ways to Test Irreducibility

Three Ways to Test Irreducibility Outline Three Ways to Test Irreducibility Richard P. Brent Australian National University joint work with Paul Zimmermann INRIA, Nancy France 8 Dec 2008 Polynomials over finite fields Irreducibility criteria

More information