Algorithms and Data Structures 2014 Exercises and Solutions Week 13

Similar documents
Let A(x) and B(x) be two polynomials of degree n 1:

The Discrete Fourier Transform

1 Generating functions for balls in boxes

Lecture 3: Divide and Conquer: Fast Fourier Transform

Polynomial Multiplication and Fast Fourier Transform

Quantum Computing Lecture 7. Quantum Factoring

Sequences and Series of Functions

Chapter 4. Fourier Series

Properties and Tests of Zeros of Polynomial Functions

ECEN 644 HOMEWORK #5 SOLUTION SET

Math 155 (Lecture 3)

Principle Of Superposition

MAT 271 Project: Partial Fractions for certain rational functions

Math 113, Calculus II Winter 2007 Final Exam Solutions

Eigenvalues and Eigenvectors

2 Geometric interpretation of complex numbers

Math 142, Final Exam. 5/2/11.

Chimica Inorganica 3

Lecture 23 Rearrangement Inequality

CALCULATION OF FIBONACCI VECTORS

Worksheet on Generating Functions

MATH 31B: MIDTERM 2 REVIEW

Solutions to Homework 1

PROBLEM SET 5 SOLUTIONS 126 = , 37 = , 15 = , 7 = 7 1.

Lemma Let f(x) K[x] be a separable polynomial of degree n. Then the Galois group is a subgroup of S n, the permutations of the roots.

SEQUENCES AND SERIES

6.003 Homework #3 Solutions

Fall 2011, EE123 Digital Signal Processing

Complex Analysis Spring 2001 Homework I Solution

Basic Sets. Functions. MTH299 - Examples. Example 1. Let S = {1, {2, 3}, 4}. Indicate whether each statement is true or false. (a) S = 4. (e) 2 S.

TMA4205 Numerical Linear Algebra. The Poisson problem in R 2 : diagonalization methods

Generating Functions II

Carleton College, Winter 2017 Math 121, Practice Final Prof. Jones. Note: the exam will have a section of true-false questions, like the one below.

3. Z Transform. Recall that the Fourier transform (FT) of a DT signal xn [ ] is ( ) [ ] = In order for the FT to exist in the finite magnitude sense,

Topic 1 2: Sequences and Series. A sequence is an ordered list of numbers, e.g. 1, 2, 4, 8, 16, or

Recurrence Relations

Solutions to Final Exam Review Problems

MATH 1910 Workshop Solution

SNAP Centre Workshop. Basic Algebraic Manipulation

TR/46 OCTOBER THE ZEROS OF PARTIAL SUMS OF A MACLAURIN EXPANSION A. TALBOT

Inverse Matrix. A meaning that matrix B is an inverse of matrix A.

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS

The Random Walk For Dummies

The Method of Least Squares. To understand least squares fitting of data.

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) =

Matrices and vectors

ANSWERS SOLUTIONS iiii i. and 1. Thus, we have. i i i. i, A.

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture)

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

11.6 Absolute Convergence and the Ratio and Root Tests

Math 105 TOPICS IN MATHEMATICS REVIEW OF LECTURES VII. 7. Binomial formula. Three lectures ago ( in Review of Lectuires IV ), we have covered

Math 110 Assignment #6 Due: Monday, February 10

Complex Numbers Solutions

INTEGRATION BY PARTS (TABLE METHOD)

(3) If you replace row i of A by its sum with a multiple of another row, then the determinant is unchanged! Expand across the i th row:

[ 11 ] z of degree 2 as both degree 2 each. The degree of a polynomial in n variables is the maximum of the degrees of its terms.

REVIEW 1, MATH n=1 is convergent. (b) Determine whether a n is convergent.

Intensive Algorithms Lecture 11. DFT and DP. Lecturer: Daniel A. Spielman February 20, f(n) O(g(n) log c g(n)).

Math 4400/6400 Homework #7 solutions

1 Last time: similar and diagonalizable matrices

We are mainly going to be concerned with power series in x, such as. (x)} converges - that is, lims N n

1 Approximating Integrals using Taylor Polynomials

MAXIMALLY FLAT FIR FILTERS

Section 1 of Unit 03 (Pure Mathematics 3) Algebra

ECE-S352 Introduction to Digital Signal Processing Lecture 3A Direct Solution of Difference Equations

Practical Spectral Anaysis (continue) (from Boaz Porat s book) Frequency Measurement

Solutions to Math 347 Practice Problems for the final

1. By using truth tables prove that, for all statements P and Q, the statement

( 1) n (4x + 1) n. n=0

Assignment 2 Solutions SOLUTION. ϕ 1 Â = 3 ϕ 1 4i ϕ 2. The other case can be dealt with in a similar way. { ϕ 2 Â} χ = { 4i ϕ 1 3 ϕ 2 } χ.

x x x Using a second Taylor polynomial with remainder, find the best constant C so that for x 0,

6.3 Testing Series With Positive Terms

Practice Test Problems for Test IV, with Solutions

MATH1035: Workbook Four M. Daws, 2009

Math 5705: Enumerative Combinatorics, Fall 2018: Homework 3

Solutions to Tutorial 3 (Week 4)

Matrix Algebra 2.2 THE INVERSE OF A MATRIX Pearson Education, Inc.

Solutions to Problem Set 8

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES

Math 116 Second Midterm November 13, 2017

6 Integers Modulo n. integer k can be written as k = qn + r, with q,r, 0 r b. So any integer.

Linear Programming and the Simplex Method

Problem Set 2 Solutions

The Binomial Theorem

(a) (b) All real numbers. (c) All real numbers. (d) None. to show the. (a) 3. (b) [ 7, 1) (c) ( 7, 1) (d) At x = 7. (a) (b)

In number theory we will generally be working with integers, though occasionally fractions and irrationals will come into play.

Polynomial Functions and Their Graphs

Finite-length Discrete Transforms. Chapter 5, Sections

Math 210A Homework 1

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Machine Learning for Data Science (CS 4786)

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

MAS160: Signals, Systems & Information for Media Technology. Problem Set 5. DUE: November 3, (a) Plot of u[n] (b) Plot of x[n]=(0.

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Statistics

Lecture 3. Digital Signal Processing. Chapter 3. z-transforms. Mikael Swartling Nedelko Grbic Bengt Mandersson. rev. 2016

Math 451: Euclidean and Non-Euclidean Geometry MWF 3pm, Gasson 204 Homework 3 Solutions

A Proof of Birkhoff s Ergodic Theorem

Estimation for Complete Data

Frequency Domain Filtering

Generating Functions. 1 Operations on generating functions

Transcription:

Algorithms ad Data Structures 204 Exercises ad Solutios Week 3 Toom-Cook (cotiued) Durig the last lecture, two polyomials A(x) a 0 + a x ad B(x) b 0 + b x both of degree were multiplied, first by evaluatig A ad B at three distict poits we picked 0, ad as cocrete values the these results were multiplied pairwise, ad fially the value represetatio of the resultig polyomial C(x) c 0 + c x + c 2 x 2 (of degree 2) was traslated back usig the iverse of the correspodig evaluatio matrix.. Repeat this procedure, but ow with 0,, as evaluatio poits. Evaluatig A at meas that we just take A s most leadig coefficiet a. Therefore, evaluatig C at (beig c 2 ) amouts to computig the product a b. 2. Explai the relatio of this procedure with Karatsuba s multiplicatio algorithm. 3. Istead of usig polyomials of degree we repeat the whole procedure with polyomials of degree 2. The the multiplicatio result will have degree 4, so we eed 5 evaluatio poits for iterpolatio (the traslatio back from values to coefficiets). Evaluate both A(x) a 0 + a x + a 2 x 2 ad B(x) b 0 + b x + b 2 x 2 at 0,,, 2,. Express the evaluatio of C(x) c 0 +c x+c 2 x 2 +c 3 x 3 +c 4 x 4 i these poits by meas of a 5 5 matrix, ad compute the iverse of this matrix. Agai, explai the relatio with the Toom-Cook3 algorithm (see exercise 4, week 2). Solutio. The evaluatio matrix correspodig to these evaluatio poits is M 00 0 0 2 0 2 0 0 0 0 0 0 ad its iverse is give by Thus, c 0 c c 2 M 0 0. 0 0 0 0 C(0) C() 0 0 C( ) 0 0 A(0)B(0) A()B() 0 0 A( )B( ) 0 0 a 0 b 0 (a 0 + a )(b 0 + b ) 0 0 a b a 0 b 0 (a 0 + a )(b 0 + b ) a 0 b 0 a b. a b You were allowed to use a computer to obtai iverse matrices.

2. The resultig formulas for the coefficiets of C are exactly the oes used by Karatsuba s multiplicatio algorithm. 3. The evaluatio matrix is ow 0 0 0 0 2 0 3 0 4 0 0 0 0 0 2 3 4 M ( ) 0 ( ) ( ) 2 ( ) 3 ( ) 4 2 0 2 2 2 2 3 2 4 2 4 8 6, 0 0 0 0 0 0 0 0 with iverse 6 0 0 0 0 M 3 6 2 2 6 6 3 3 0 6 3 3 2. 0 0 0 0 6 Now we have c 0 6 0 0 0 0 C(0) c c 2 c 3 3 6 2 2 C() 6 6 3 3 0 6 C( ) 3 3 2 C(2) c 4 0 0 0 0 6 C( ) 6 0 0 0 0 A(0)B(0) 3 6 2 2 A()B() 6 6 3 3 0 6 A( )B( ) 3 3 2 A(2)B(2) 0 0 0 0 6 A( )B( ) 6 0 0 0 0 a 0 b 0 3 6 2 2 (a 0 + a + a 2 )(b 0 + b + b 2 ) 6 6 3 3 0 6 (a 0 a + a 2 )(b 0 b + b 2 ) 3 3 2 (a 0 + 2a + 4a 2 )(b 0 + 2b + 4b 2 ). 0 0 0 0 6 a 2 b 2 With some imagiatio, these are see to be precisely the calculatios performed by Toom- Cook3. 2 Fast Fourier Trasform 2. Evaluatio Give a algorithm that evaluates a polyomial A(x) a 0 + a x + a 2 x 2 + + a x at poit x i O() time. Solutio : fuctio EVAL(A, x) 2: v 0 3: p 4: for i from 0 to do 5: v v + a i p 6: p x p 7: retur v

2.2 Basic properties of th roots of uity. What is the sum of the th roots of uity? 2. What is their product if is odd? If is eve? Solutio. For, the oly th root of uity is ω 0 cos 2π 0 + i si 2π 0. Now suppose >. Usig the formula for a geometric series, we see that ω k ω ω cos 2π 2π + i si ω cos(2π) + i si(2π) ω cos(2π) ω ω 0 ω 0. 2. Usig the laws show durig the lecture, we fid that 2.3 Iverse FFT ( ω k cos 2π k + i si 2π k ) ( ) ( ) 2π k 2π k cos + i si ( ) ( ) 2π 2π cos k + i si k ( ) ( ) 2π( ) 2π( ) cos + i si 2 2 cos(π( )) + i si(π( )) cos(π( )) { if is eve otherwise. Show that the matrices M(, ω, ω 2,..., ω ) ad M(, ω, ω 2,..., ω ( ) ) are ideed iverses of each other. Hit: Show that their product is the idetity matrix. Solutio We ame M M(, ω, ω 2,..., ω ) ad N M(, ω, ω 2,..., ω ( ) ). That is, M ij ω ij ad N ij ω ij if we umber the idices from 0 to. We wat to show that

MN I, where I is the idetity matrix. We have (MN) ij M ik N kj ω ik ω kj (ω i j ) k. Obviously, this yields if i j, givig us the desired diagoal. If i j, we use agai the geometric series formula to obtai (ω i j ) k (ωi j ) ω i j cos 2π(i j) + i si 2π(i j) ω i j cos(2π(i j)) + i si(2π(i j)) ω i j ω i j 0 ω i j 0. 2.4 Practice with the fast Fourier Trasform. What is the FFT of (, 0, 0, 0) What is the appropriate value of ω i this case? Ad of which sequece is (, 0, 0, 0) the FFT? 2. Repeat for (, 0,, ). Solutio. We are give 4 coefficiets, so ω cos 2π 4 + i si 2π 4 i. However, i this case the value of ω is irrelevat, sice FFT((, 0, 0, 0), ω) ω ω 2 ω 3 0 ω 2 ω 4 ω 6 0 ω 3 ω 6 ω 9 0.

The same holds for the iverse FFT, as FFT 0 0 4 FFT((, 0, 0, 0), ω ) 0 ω ω 2 ω 3 0 4 ω 2 ω 4 ω 6 0 ω 3 ω 6 ω 9 0 4. 2. Now we have (fillig i i for ω as obtaied i the previous part) FFT((, 0,, ), i) i i 2 i 3 0 i 2 i 4 i 6 i 3 i 6 i 9 i i 0 i i i 3. i Note that i i i 2 i i. Therefore, FFT 0 FFT((, 0,, ), i) 4 i i 2 i 3 0 4 i 2 i 4 i 6 i 3 i 6 i 9 i i 0 4 i i i 4. 2.5 Practice with polyomial multiplicatio by FFT 3 i. Suppose that you wat to multiply the two polyomials x + ad x 2 + usig the FFT. Choose a appropriate power of two, fid the FFT of the two sequeces, multiply the results

compoetwise, ad compute the iverse FFT to get the fial result. 2. Repeat for the pair of polyomials + x + 2x 2 ad 2 + 3x. Solutio. Multiplicatio of a polyomial of degree with a polyomial of degree 2 yields a polyomial of degree 3. Obviously, 3 < 4, ad 4 is a power of 2. As i the previous exercise, ω i. The FFT of the first polyomial is FFT((,, 0, 0), i) i i 2 i 3 i 2 i 4 i 6 0 i 3 i 6 i 9 0 i i 0 i i 0 2 + i 0. i For the secod polyomial we have FFT((, 0,, 0), i) i i 2 i 3 0 i 2 i 4 i 6 i 3 i 6 i 9 0 i i 0 i i 0 2 0 2. 0 The coefficiets of the product polyomial are ow give by the iverse FFT of the poitwise product of these value represetatios. That is, 4 FFT 0 0 4 FFT((4, 0, 0, 0), i ) 0 4 i i 2 i 3 0 4 i 2 i 4 i 6 0 i 3 i 6 i 9 0. We coclude that the resultig polyomial is + x + x 2 + x 3.

2. We still have ω i. I this case, the FFT of the first polyomial is FFT((,, 2, 0), i) i i 2 i 3 i 2 i 4 i 6 2 i 3 i 6 i 9 0 i i 2 i i 0 4 i 2. i For the secod polyomial we have 2 FFT((2, 3, 0, 0), i) i i 2 i 3 3 i 2 i 4 i 6 0 i 3 i 6 i 9 0 2 i i 3 0 i i 0 5 2 + 3i. 2 3i Now we obtai the coefficiets of the product polyomial as 20 FFT 5 i 2 4 FFT((20, 5 i, 2, i 5), i ) i 5 20 i i 2 i 3 5 i 4 i 2 i 4 i 6 2 i 3 i 6 i 9 i 5 20 i i 5 i 4 2 i i i 5 2 5 7, 6 so the product polyomial is 2 + 5x + 7x 2 + 6x 3.

3 FFT i modular arithmetic This exercise illustrates how to do the Fourier Trasform (FT) i modular arithmetic, for example, modulo 7.. There is a umber ω such that all the powers ω 0, ω,..., ω 5 are distict (modulo 7). Fid this ω ad show that ω 0 + ω + + ω 5 0 (modulo 7). 2. Usig the matrix form of the FT, produce the trasform of the sequece (0,,,, 5, 2) modulo 7; that is, multiply this vector by the matrix M(ω 0, ω,..., ω 5 ). I the matrix multiplicatio, all calculatios should be performed modulo 7. 3. Write dow the matrix ecessary to perform the iverse FT. Show that multiplyig by this matrix returs the origial sequece. (Agai all arithmetic should be performed modulo 7.) 4. Now show how to multiply the polyomials x 2 + x + ad x 3 + 2x usig the FT modulo 7.