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

Size: px
Start display at page:

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

Transcription

1 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 solving these subproblems 3 Appropriately combining their answers Multiplication Johann Carl Friedrich Gauss = 100 ( ) 2 =5050 Suppose x and y are two n-bit integers, and assume for convenience that n is a power of 2 Gauss once noticed that although the product of two complex numbers (a + bi)(c + di) =ac bd +(bc + ad)i seems to involve four real-number multiplications, it can in fact be done with just three: ac, bd, and(a + b)(c + d), since bc + ad =(a + b)(c + d) ac bd n our big-o way of thinking, reducing the number of multiplications from four to three seems wasted ingenuity But this modest improvement becomes very significant when applied recursively Lemma For every n there exists an n 0 with n apple n 0 apple 2n such that n 0 apowerof2 As a first step toward multiplying x and y, wespliteachofthemintotheirleft and right halves, which are n/2 bits long: x = x L x R =2 n/2 x L + x R y = y L y R =2 n/2 y L + y R xy =(2 n/2 x L + x R)(2 n/2 y L + y R)=2 n x Ly L +2 n/2 (x Ly R + x Ry L)+x Ry R The additions take linear time, as do the multiplications by powers of 2 The significant operations are the four n/2-bit multiplications; these we can handle by four recursive calls

2 A divide-and-conquer algorithm for integer multiplication Our method for multiplying n-bit numbers starts by making recursive calls to multiply these four pairs of n/2-bit numbers, and then evaluates the preceding expression in O(n) time Writing T (n) for the overall running time on n-bit inputs, we get the recurrence relation: T (n) =4T (n/2) + O(n) Solution: O(n 2 ) By Gauss s trick, three multiplications, x Ly L, x Ry R,and(x L + x R)(y L + y R), su ce, as x Ly R + x Ry L =(x L + x R)(y L + y R) x Ly L x Ry R multiply(x, y) // nput: positive integers x and y, in binary // Output: their product 1 n =max(sizeofx, sizeofy) roundedasapowerof2 2 if n =1then return xy 3 x L, x R = leftmost n/2, rightmost n/2 bitsofx 4 y L, y R = leftmost n/2, rightmost n/2 bitsofy 5 P 1 = multiply(x L, y L) 6 P 2 = multiply(x R, y R) 7 P 3 = multiply(x L + x R, y L + y R) 8 return P 1 2 n +(P 3 P 1 P 2) 2 n/2 + P 2 The time analysis The recurrence relation: T (n) =3T (n/2) + O(n) The algorithm s recursive calls form a tree structure At each successive level of recursion the subproblems get halved in size At the (log 2 n) th level, the subproblems get down to size 1, and so the recursion ends The height of the tree is log 2 n The branching factor is 3: each problem recursively produces three smaller ones, with the result that at depth k in the tree there are 3 k subproblems, eachofsize n/2 k For each subproblem, a linear amount of work is done in identifying further subproblems and combining their answers Therefore the total time spent at depth k in the tree is 3 k n k 3 O = O(n) 2 k 2 The time analysis (cont d) 3 k n k 3 O = O(n) 2 k 2 At the very top level, when k =0,weneedO(n) At the bottom, when k =log 2 n,itis O 3 log n 2 = O n log 3 2 Between these two endpoints, the work done increases geometrically from O(n) to O(n log 2 3 ), by a factor of 3/2 perlevel The sum of any increasing geometric series is, within a constant factor, simply the last term of the series Therefore the overall running time is We can do even better! O(n log 2 3 ) O(n 159 ) Master theorem Recurrence relations f T (n) =at (dn/be)+o(n d ) for some constants a > 0, b > 1, and d 0, then 8 >< O(n d ) if d > log b a T (n) = O(n d log n) if d =log b a >: O(n log b a ) if d < log b a

3 Proof of Master Theorem Proof of Master Theorem Assume that n is a power of b This will not influence the final bound in any important way: n is at most a multiplicative factor of b away from some power of b Next, notice that the size of the subproblems decreases by a factor of b with each level of recursion, and therefore reaches the base case after log b n levels This is the height of the recursion tree The branching factor of the recursion tree is a, sothekth level of the tree is made up of a k subproblems, eachofsize n = b k The total work done at this level is a k O n b k d = O(n d ) a b d k The total work done is log n b X k=0 a k n d O = O(n d a k ) b k b d t s the sum of a geometric series with ratio a/b d 1 The ratio is less than 1 Then the series is decreasing, and its sum is just given by its first term, O(n d ) 2 The ratio is greater than 1 The series is increasing and its sum is given by its last term, O(n log b a ): n d a logb n = n d a log b n = a log b n = a (log a n)(log b a) = n log b a b d (b log b n ) d 3 The ratio is exactly 1 n this case all O(log n) termsoftheseriesare equal to O(n d ) The algorithm Merge sort mergesort(a[1 n]) // nput: an array of numbers a[1 n] // Output: A sorted version of this array 1 if n > 1 then 2 return merge(mergesort(a[1 bn/2c]), 3 mergesort(a[bn/2c +1n]), 4 else return a merge(x[1 k], y[1 `]) // nput: two sorted arrays x and y // Output: A sorted version of the union of x and y 1 if k =0then return y[1 `] 2 if ` =0then return x[1 k] 3 if x[1] apple y[1] 4 then return x[1] merge(x[2 k], y[1 `]) 5 else return y[1] merge(x[1 k], y[2 `]) The time analysis An n log n lower bound for sorting Sorting algorithms can be depicted as trees The recurrence relation: T (n) =2T (n/2) + O(n); By Master Theorem T (n) =O(n log n) The depth of the tree the number of comparisons on the longest path from root to leaf, is exactly the worst-case time complexity of the algorithm Consider any such tree that sorts an array of n elements Each of its leaves is labeled by a permutation of {1, 2,,n} every permutation must appear as the label of a leaf This is a binary tree with n! leaves So, the depth of our tree and the complexity of our algorithm must be at least log(n!) log p (2n +1/3) nn e n = (n log n), where we use Stirling s formula

4 Median Median The median of a list of numbers is its 50th percentile: half the numbers are bigger than it, and half are smaller f the list has even length, there are two choices for what the middle element could be, in which case we pick the smaller of the two, say The purpose of the median is to summarize a set of numbers by a single, typical value Computing the median of n numbers is easy: just sort them The drawback is that this takes O(n log n) time,whereaswewouldideallylikesomethinglinear We have reason to be hopeful, because sorting is doing far more work than we really need we just want the middle element and don t care about the relative ordering of the rest of them Selection A randomized divide-and-conquer algorithm for selection nput: AlistofnumbersS; anintegerk Output: Thekth smallest element of S For any number v, imaginesplittinglists into three categories: elements smaller than v, ie,s L; those equal to v, ie,s v (there might be duplicates); and those greater than v, ie,s R respectively 8 >< selection(s L, k) if k apple S L selection(s, k) = v if S L < k apple S L + S v >: selection(s R, k S L S v ) if k > S L + S v How to choose v? How to choose v? (cont d) t should be picked quickly, and it should shrink the array substantially, the ideal situation being S L, S R S 2 f we could always guarantee this situation, we would get a running time of T (n) =T (n/2) + O(n) =O(n) But this requires picking v to be the median, which is our ultimate goal! nstead, we follow a much simpler alternative: we pick v randomly from S Worst-case scenario would force our selection algorithm to perform Best-case scenario: O(n) n +(n 1) + (n 2) + + n 2 = (n2 ) Where, in this spectrum from O(n) to (n 2 ), does the average running time lie? Fortunately, it lies very close to the best-case time

5 The e ciency analysis The e ciency analysis (cont d) v is good if it lies within the 25th to 75th percentile of the array that it is chosen from Arandomlychosenvhasa50% chance of being good, Lemma On average a fair coin needs to be tossed two times before a heads is seen Proof Let T (n) betheexpected running time on an array of size n, weget T (n) apple T (3n/4) + O(n) =O(n) E := expected number of tosses before head is seen We need at least one toss, and it s heads, we re done f it s tail (with probability 1/2), we need to repeat Hence whose solution is E =2 E = E, Matrix multiplication The product of two n n matrices X and Y is a third n n matrix Z = XY, with (i, j)th entry nx Z ij = k=1 X iky kj That is, Z ij is the dot product of the ith row of X with the jth column of Y n general, XY is not the same as YX ; matrix multiplication is not commutative The preceding formula implies an O(n 3 ) algorithm for matrix multiplication Divide and conquer apple apple A B E X = C D, Y = G F H Then apple A XY = C B D apple E F apple AE + BG G H = CE + DG AF + BH CF + DH To compute the size-n product XY,recursively compute eight size-n/2 products AE, BG, AF, BH, CE, DG, CF, DH and then do some O(n 2 )-time addition Volker Strassen (1936 ) n 1969, the German mathematician Volker Strassen announced a surprising O(n 281 ) algorithm The recurrence is with solution O(n 3 ) T (n) =8T (n/2) + O(n 2 )

6 Strassen s trick where apple P5 + P 4 P 2 + P 6 P 1 + P 2 XY = P 3 + P 4 P 1 + P 5 = P 3 P 7 P 1 = A(F H) P 5 = (A + D)(E + H) P 2 = (A + B)H P 6 = (B D)(G + H) P 3 = (C + D)E P 7 = (A C)(E + F ) P 4 = D(G E) Faster Polynomial Multiplication The recurrence is with solution O(n log 2 7 ) O(n 281 ) T (n) =7T (n/2) + O(n 2 ) 1/6 Let A and B be polynomials of degree at most n: nx A(x) = a j x j for some a 0,,a n 2 R, j=0 nx B(x) = b j x j for some b 0,,b n 2 R j=0 Wish to calculate C(x) =A(x)B(x) Necessarily, deg(c) =2n and so C(x) = for some c 0,,c 2n 2 R 2nX j=0 c j x j Problem: Given coe cients of A and B, compute coe s of C Easy to see that c j = jx a i b j i (0 apple j apple 2n) i=0 This suggests the naive algorithm : for (int j 2 {0,,2n}) do c j =0 for (int i 2 {0,,j}) do c j += a i b j 1 Use the real-number model of computation: arithmetic operation on real numbers has unit cost Cost of naive algorithm? (n 2 ) Can we do better? Yes! 2/6 3/6 Without loss of generality, assume n a power of two Write A(x) =A 1 (x)x n/2 + A 2 (x) B(x) =B 1 (x)x n/2 + B 2 (x) where deg A 1 =dega 2 =degb 1 =degb 2 = n/2 Then C(x) =A 1 (x)b 1 (x)x n + A 2 (x)b 1 (x)+a 1 (x)b 2 (x) x n/2 +A 2 (x)b 2 (x) Use Gauss trick: P 1 (x) =A 1 (x)b 1 (x) P 2 (x) =A 2 (x)b 2 (x) P 3 (x) = A 1 (x)+a 2 (x) B 1 (x)+b 2 (x) S(x) =P 3 (x) P 1 (x) P 2 (x) C(x) =P 1 (x)x n + S(x)x n/2 + P 2 (x) We then find T (n) =3T (n/2) + (n) By the Master Theorem, we have T (n) = (n log 2 3 ) = (n 159 ) Can we do better? Yes! 4/6 5/6

7 f we follow the approach that the Toom-Cook algorithms uses in multiplying n-bit numbers, we can show 8" > 0, we can multiply two polnomials of degree n using (n 1+" ) arithmetic operations The fast Fourier transform However, the -constnat blows up as "! 0 Can we do better? Yes! (use the Fast Fourier transform) 6/6 Polynomial multiplication An alternative representation of polynomials f A(x) =a 0 + a 1x + + a dx d and B(x) =b 0 + b 1x + + b dx d, their product has coe cients C(x) =A(x) B(x) =c 0 + c 1x + + c 2dx 2d c k = a 0b k + a 1b k a kb 0 = where for i > d, takea i and b i to be zero kx a ib k Computing c k from this formula takes O(k) steps, and finding all 2d +1 coe cients would therefore seem to require (d 2 ) time i=0 i Fact Adegree-dpolynomialisuniquelycharacterizedbyitsvaluesatanyd+1 distinct points Eg, any two points determine a line We can specify a degree-d polynomial A(x) =a 0 + a 1x + + a dx d by either one of the following: 1 ts coe cients a 0, a 1,,a d(coe cient representation) 2 The values A(x 0), A(x 1),,A(x d) (value representation) An alternative representation of polynomials (cont d) The algorithm coe cient representation evaluation interpolation! value representation - The product C(x) hasdegree2d, itiscompletelydeterminedbyitsvalue at any 2d +1points - The value of C(z) atanygivenpointz is just A(z) timesb(z) Thus polynomial multiplication takes linear time in the value representation nput: Coe cients of two polynomials, A(x) andb(x), of degree d Output: Their product C = A B Selection Pick some points x 0, x 1,,x n 1, wheren 2d +1 Evaluation Compute A(x 0), A(x 1),,A(x n 1) andb(x 0), B(x 1),,B(x n 1) Multiplication Compute C(x k)=a(x k)b(x k) for all k =0,,n 1 nterpolation Recover C(x) =c 0 + c 1x + + c 2dx 2d

8 Evaluation by divide-and-conquer The selection step and the n multiplications are just linear time: n a typical setting for polynomial multiplication, the coe cients of the polynomials are real numbers and, moreover, are small enough that basic arithmetic operations (adding and multiplying) take unit time Evaluating a polynomial of degree d apple n at a single point takes O(n), and so the baseline for n points is (n 2 ) The fast Fourier transform (FFT) does it in just O(n log n) time, for a particularly clever choice of x 0,,x n 1 in which the computations required by the individual points overlap with one another and can be shared We pick the n points: ±x 0, ±x 1,,±x n/2 1, then the computations required for each A(x i)anda( x i)overlapalot, because the even powers of x i coincide with those of x i To investigate this, we need to split A(x) into its odd and even powers, for instance 3+4x +6x 2 +2x 3 + x 4 +10x 5 = (3 + 6x 2 + x 4 ) + x(4 + 2x 2 +10x 4 ) More generally A(x) =A e(x 2 ) + xa o(x 2 ), where A e( ), with the even-numbered coe cients, and A o( ), with the odd-numbered coe cients, are polynomials of degree apple n/2 1 (assume for convenience that n is even) Evaluation by divide-and-conquer (cont d) How to choose n points? Given paired points ±x i, the calculations needed for A(x i)canberecycled toward computing A( x i): A(x i)=a e(x 2 i )+x ia o(x 2 i ) A( x i)=a e(x 2 i ) x ia o(x 2 i ) n other words, evaluating A(x) atn paired points ±x 0,,±x n/2 1 reduces to evaluating A e(x) anda o(x) (whicheachhavehalfthedegreeofa(x)) at just n/2 points,x0 2,,x 2 n/2 1 f we could recurse, wewouldgetadivide-and-conquerprocedurewithrunning time T (n) =2T (n/2) + O(n) =O(n log n) We have a problem: To recurse at the next level, we need the n/2 evaluation points x0 2, x1 2,,x 2 n/2 1 to be themselves plus-minus pairs How can a square be negative? We use complex numbers At the very bottom of the recursion, we have a single point This point might as well be 1, in which case the level above it must consist of its square roots, ± p 1=±1 The next level up then has ± p +1 = ±1 aswellasthecomplexnumbers ± p 1=±i, wherei is the imaginary unit By continuing in this manner, we eventually reach the initial set of n points: the complex nth roots of unity, thatis,then complex solutions to the equation z n =1 The complex roots of unity The fast Fourier transform (polynomial formulation) The nth roots of unity: the complex numbers where f n is even, then: 1,!,! 2,,! n 1,! = e 2 i/n 1 The nth roots are plus-minus paired,! n/2+j =! j 2 Squaring them produces the (n/2)nd roots of unity Therefore, if we start with these numbers for some n that is a power of 2, then at successive levels of recursion we will have the (n/2 k )th roots of unity, for k =0, 1, 2, 3, All these sets of numbers are plus-minus paired, and so our divide-and-conquer, works perfectly The resulting algorithm is the fast Fourier transform FFT(A,!) nput: coe cient representation of a polynomial A(x) of degree apple n 1, where n is a power of 2;!, annth root of unity Output: value representation A(! 0 ),,A(! n 1 ) 1 if! =1then return A(1) 2 express A(x) in the form A e(x 2 )+xa o(x 2 ) 3 call FFT(A e,! 2 )toevaluatea e at even powers of! 4 call FFT(A o,! 2 )toevaluatea o at even powers of! 5 for j =0to n 1 do 6 compute A(! j )=A e(! 2j )+! j A o(! 2j ) 7 return A(! 0 ),,A(! n 1 )

9 nterpolation A matrix reformulation We designed the FFT, a way to move from coe cients to values in time just O(n log n), when the points {x i} are complex nth roots of unity That is 1,!,! 2,,! n 1 hvaluei = FFT hcoe cientsi,! We will see that the interpolation can be computed by hcoe cientsi = 1 FFT hvaluesi,! n Let s explicitly set down the relationship between our two representations for a polynomial A(x) ofdegreeapple n A(x 0) A(x 1) A(x n 1) x 0 x0 2 x n = 1 x 1 x1 2 x n x n 1 xn 2 1 x n 1 n 1 a 0 a 1 a n 1 Let M be the matrix in the middle, which is a Vandermonde matrix: f x 0,,x n 1 are distinct numbers, then M is invertible Hence Evaluation is multiplication by M, while interpolation is multiplication by M nterpolation resolved nterpolation resolved (cont d) n linear algebra terms, the FFT multiplies an arbitrary n-dimensional vector which we have been calling the coe cient representation bythen n matrix !! 2! n 1 M n(!) = 1! j! 2j (n 1)j! ! n 1! 2(n 1) (n 1)(n 1)! ts (j, k)th entry (starting row- and column-count at zero) is! jk We will show: nversion formula M n(!) 1 = 1 n Mn! 1 Take! to be e 2 i/n and think of the columns of M as vectors in C n Recall that the angle between two vectors u =(u 0,,u n 1) andv =(v 0,,v n 1) in C n is just a scaling factor times their inner product u v = u 0v 0 + u 1v u n 1v n 1, where z denotes the complex conjugate of z Recall the complex conjugate of a complex number z = re i is z = re i The complex conjugate of a vector (or matrix) is obtained by taking the complex conjugates of all its entries The above quantity is maximized when the vectors lie in the same direction and is zero when the vectors are orthogonal to each other nterpolation resolved (cont d) The fast Fourier transform (general formulation) Lemma The columns of matrix M are orthogonal to each other Proof Take the inner product of any columns j and k of matrix M, 1+! j k +! 2(j k) + +! (n 1)(j k) This is a geometric series with first term 1, last term! (n 1)(j k),andratio! j k Therefore, if j 6= k, thenitevaluatesto f j = k, thenitevaluateston Corollary MM = n, ie, n(j k) 1! =0 1! (j k) M n(!) 1 = 1 n Mn(! 1 ) FFT(a,!) nput: An array a =(a 0, a 1,,a n 1) for n apowerof2 Aprimitiventh root of unity,! Output: M n(!) 1 if! =1then return a 2 (s 0, s 1,,s n/2 1 )=FFT((a 0, a 2,,a n 2),! 2 ) 3 (s0, 0 s1,,s 0 n 0 2) =FFT((a 1, a 3,,a n 1),! 2 ) 4 for j =0to n/2 1 do 5 r j = s j +! j sj 0 6 r j+n/2 = s j! j sj 0 7 return (r 0, r 1,,r n 1)

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

Divide-and-conquer algorithms

Divide-and-conquer algorithms 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

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

Divide and Conquer CPE 349. Theresa Migler-VonDollen

Divide and Conquer CPE 349. Theresa Migler-VonDollen Divide and Conquer CPE 349 Theresa Migler-VonDollen Divide and Conquer Divide and Conquer is a strategy that solves a problem by: 1 Breaking the problem into subproblems that are themselves smaller instances

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

Divide-and-Conquer and Recurrence Relations: Notes on Chapter 2, Dasgupta et.al. Howard A. Blair

Divide-and-Conquer and Recurrence Relations: Notes on Chapter 2, Dasgupta et.al. Howard A. Blair Divide-and-Conquer and Recurrence Relations: Notes on Chapter 2, Dasgupta et.al. Howard A. Blair 1 Multiplication Example 1.1: Carl Friedrich Gauss (1777-1855): The multiplication of two complex numbers

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

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Chapter 2 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: Room 5326, Engineering Building, Thursday 4:30pm -

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

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms Introduction There exist many problems that can be solved using a divide-and-conquer algorithm. A divide-andconquer algorithm A follows these general guidelines. Divide Algorithm

More information

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015 CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015 1 Introduction The divide-and-conquer strategy is a general paradigm for algorithm design. This strategy

More information

The Fast Fourier Transform

The Fast Fourier Transform The Fast Fourier Transform 1 Motivation: digital signal processing The fast Fourier transform (FFT) is the workhorse of digital signal processing To understand how it is used, consider any signal: any

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

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

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

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

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

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

ELEMENTARY LINEAR ALGEBRA

ELEMENTARY LINEAR ALGEBRA ELEMENTARY LINEAR ALGEBRA K. R. MATTHEWS DEPARTMENT OF MATHEMATICS UNIVERSITY OF QUEENSLAND Second Online Version, December 1998 Comments to the author at krm@maths.uq.edu.au Contents 1 LINEAR EQUATIONS

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

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

ELEMENTARY LINEAR ALGEBRA

ELEMENTARY LINEAR ALGEBRA ELEMENTARY LINEAR ALGEBRA K R MATTHEWS DEPARTMENT OF MATHEMATICS UNIVERSITY OF QUEENSLAND First Printing, 99 Chapter LINEAR EQUATIONS Introduction to linear equations A linear equation in n unknowns x,

More information

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2. Chapter 1 LINEAR EQUATIONS 11 Introduction to linear equations A linear equation in n unknowns x 1, x,, x n is an equation of the form a 1 x 1 + a x + + a n x n = b, where a 1, a,, a n, b are given real

More information

Introduction to Divide and Conquer

Introduction to Divide and Conquer Introduction to Divide and Conquer Sorting with O(n log n) comparisons and integer multiplication faster than O(n 2 ) Periklis A. Papakonstantinou York University Consider a problem that admits a straightforward

More information

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk CMPS 2200 Fall 2017 Divide-and-Conquer Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 1 The divide-and-conquer design paradigm 1. Divide the problem (instance)

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

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

APPENDIX A. Background Mathematics. A.1 Linear Algebra. Vector algebra. Let x denote the n-dimensional column vector with components x 1 x 2.

APPENDIX A. Background Mathematics. A.1 Linear Algebra. Vector algebra. Let x denote the n-dimensional column vector with components x 1 x 2. APPENDIX A Background Mathematics A. Linear Algebra A.. Vector algebra Let x denote the n-dimensional column vector with components 0 x x 2 B C @. A x n Definition 6 (scalar product). The scalar product

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 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version)

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version) CS 470/570 Divide-and-Conquer Format of Divide-and-Conquer algorithms: Divide: Split the array or list into smaller pieces Conquer: Solve the same problem recursively on smaller pieces Combine: Build the

More information

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14 Divide and Conquer Algorithms CSE 101: Design and Analysis of Algorithms Lecture 14 CSE 101: Design and analysis of algorithms Divide and conquer algorithms Reading: Sections 2.3 and 2.4 Homework 6 will

More information

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science Divide & Conquer Jordi Cortadella and Jordi Petit Department of Computer Science Divide-and-conquer algorithms Strategy: Divide the problem into smaller subproblems of the same type of problem Solve the

More information

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science Divide & Conquer Jordi Cortadella and Jordi Petit Department of Computer Science Divide-and-conquer algorithms Strategy: Divide the problem into smaller subproblems of the same type of problem Solve the

More information

ELEMENTARY LINEAR ALGEBRA

ELEMENTARY LINEAR ALGEBRA ELEMENTARY LINEAR ALGEBRA K R MATTHEWS DEPARTMENT OF MATHEMATICS UNIVERSITY OF QUEENSLAND Second Online Version, December 998 Comments to the author at krm@mathsuqeduau All contents copyright c 99 Keith

More information

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example Recurrence Relations Chapter 2 Divide and Conquer Equation or an inequality that describes a function by its values on smaller inputs. Recurrence relations arise when we analyze the running time of iterative

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

A matrix over a field F is a rectangular array of elements from F. The symbol

A matrix over a field F is a rectangular array of elements from F. The symbol Chapter MATRICES Matrix arithmetic A matrix over a field F is a rectangular array of elements from F The symbol M m n (F ) denotes the collection of all m n matrices over F Matrices will usually be denoted

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

ELEMENTARY LINEAR ALGEBRA

ELEMENTARY LINEAR ALGEBRA ELEMENTARY LINEAR ALGEBRA K. R. MATTHEWS DEPARTMENT OF MATHEMATICS UNIVERSITY OF QUEENSLAND Corrected Version, 7th April 013 Comments to the author at keithmatt@gmail.com Chapter 1 LINEAR EQUATIONS 1.1

More information

Practical Session #3 - Recursions

Practical Session #3 - Recursions Practical Session #3 - Recursions Substitution method Guess the form of the solution and prove it by induction Iteration Method Convert the recurrence into a summation and solve it Tightly bound a recurrence

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

Linear Algebra March 16, 2019

Linear Algebra March 16, 2019 Linear Algebra March 16, 2019 2 Contents 0.1 Notation................................ 4 1 Systems of linear equations, and matrices 5 1.1 Systems of linear equations..................... 5 1.2 Augmented

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

Elementary maths for GMT

Elementary maths for GMT Elementary maths for GMT Linear Algebra Part 2: Matrices, Elimination and Determinant m n matrices The system of m linear equations in n variables x 1, x 2,, x n a 11 x 1 + a 12 x 2 + + a 1n x n = b 1

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

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

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

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Algorithms (II) Yu Yu. Shanghai Jiaotong University Algorithms (II) Yu Yu Shanghai Jiaotong University Chapter 1. Algorithms with Numbers Two seemingly similar problems Factoring: Given a number N, express it as a product of its prime factors. Primality:

More information

= main diagonal, in the order in which their corresponding eigenvectors appear as columns of E.

= main diagonal, in the order in which their corresponding eigenvectors appear as columns of E. 3.3 Diagonalization Let A = 4. Then and are eigenvectors of A, with corresponding eigenvalues 2 and 6 respectively (check). This means 4 = 2, 4 = 6. 2 2 2 2 Thus 4 = 2 2 6 2 = 2 6 4 2 We have 4 = 2 0 0

More information

Divide and Conquer. Arash Rafiey. 27 October, 2016

Divide and Conquer. Arash Rafiey. 27 October, 2016 27 October, 2016 Divide the problem into a number of subproblems Divide the problem into a number of subproblems Conquer the subproblems by solving them recursively or if they are small, there must be

More information

INSTITIÚID TEICNEOLAÍOCHTA CHEATHARLACH INSTITUTE OF TECHNOLOGY CARLOW MATRICES

INSTITIÚID TEICNEOLAÍOCHTA CHEATHARLACH INSTITUTE OF TECHNOLOGY CARLOW MATRICES 1 CHAPTER 4 MATRICES 1 INSTITIÚID TEICNEOLAÍOCHTA CHEATHARLACH INSTITUTE OF TECHNOLOGY CARLOW MATRICES 1 Matrices Matrices are of fundamental importance in 2-dimensional and 3-dimensional graphics programming

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 310 Advanced Data Structures and Algorithms Runtime Analysis May 31, 2017 Tong Wang UMass Boston CS 310 May 31, 2017 1 / 37 Topics Weiss chapter 5 What is algorithm analysis Big O, big, big notations

More information

CS361 Homework #3 Solutions

CS361 Homework #3 Solutions CS6 Homework # Solutions. Suppose I have a hash table with 5 locations. I would like to know how many items I can store in it before it becomes fairly likely that I have a collision, i.e., that two items

More information

Lecture 8 - Algebraic Methods for Matching 1

Lecture 8 - Algebraic Methods for Matching 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) February 1, 2018 Lecture 8 - Algebraic Methods for Matching 1 In the last lecture we showed that

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

Matrices. Chapter What is a Matrix? We review the basic matrix operations. An array of numbers a a 1n A = a m1...

Matrices. Chapter What is a Matrix? We review the basic matrix operations. An array of numbers a a 1n A = a m1... Chapter Matrices We review the basic matrix operations What is a Matrix? An array of numbers a a n A = a m a mn with m rows and n columns is a m n matrix Element a ij in located in position (i, j The elements

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

More information

Legendre s Equation. PHYS Southern Illinois University. October 18, 2016

Legendre s Equation. PHYS Southern Illinois University. October 18, 2016 Legendre s Equation PHYS 500 - Southern Illinois University October 18, 2016 PHYS 500 - Southern Illinois University Legendre s Equation October 18, 2016 1 / 11 Legendre s Equation Recall We are trying

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

CS173 Running Time and Big-O. Tandy Warnow

CS173 Running Time and Big-O. Tandy Warnow CS173 Running Time and Big-O Tandy Warnow CS 173 Running Times and Big-O analysis Tandy Warnow Today s material We will cover: Running time analysis Review of running time analysis of Bubblesort Review

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

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

SMT 2013 Power Round Solutions February 2, 2013

SMT 2013 Power Round Solutions February 2, 2013 Introduction This Power Round is an exploration of numerical semigroups, mathematical structures which appear very naturally out of answers to simple questions. For example, suppose McDonald s sells Chicken

More information

6.S897 Algebra and Computation February 27, Lecture 6

6.S897 Algebra and Computation February 27, Lecture 6 6.S897 Algebra and Computation February 7, 01 Lecture 6 Lecturer: Madhu Sudan Scribe: Mohmammad Bavarian 1 Overview Last lecture we saw how to use FFT to multiply f, g R[x] in nearly linear time. We also

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

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. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai Divide-and-Conquer Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, 33.4. CSE 6331 Algorithms Steve Lai Divide and Conquer Given an instance x of a prolem, the method works as follows: divide-and-conquer

More information

shelat divide&conquer closest points matrixmult median

shelat divide&conquer closest points matrixmult median L6feb 9 2016 shelat 4102 divide&conquer closest points matrixmult median 7.5 7.8 9.5 3.7 26.1 closest pair of points simple brute force approach takes 14 1 2 7 8 9 4 13 3 10 11 5 12 6 solve the large problem

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

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 CS17 Integrated Introduction to Computer Science Klein Contents Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 1 Tree definitions 1 2 Analysis of mergesort using a binary tree 1 3 Analysis of

More information

1 Locally computable randomized encodings

1 Locally computable randomized encodings CSG399: Gems of Theoretical Computer Science Lectures 3-4 Feb 20-24, 2009 Instructor: Emanuele Viola Scribe: Eric Miles Cryptography in constant depth: II & III Locally computable randomized encodings

More information

Review Of Topics. Review: Induction

Review Of Topics. Review: Induction Review Of Topics Asymptotic notation Solving recurrences Sorting algorithms Insertion sort Merge sort Heap sort Quick sort Counting sort Radix sort Medians/order statistics Randomized algorithm Worst-case

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

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

Advanced Counting Techniques

Advanced Counting Techniques . All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education. Advanced Counting

More information

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Divide-and-conquer: Order Statistics. Curs: Fall 2017 Divide-and-conquer: Order Statistics Curs: Fall 2017 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers.

More information

ICS 6N Computational Linear Algebra Matrix Algebra

ICS 6N Computational Linear Algebra Matrix Algebra ICS 6N Computational Linear Algebra Matrix Algebra Xiaohui Xie University of California, Irvine xhx@uci.edu February 2, 2017 Xiaohui Xie (UCI) ICS 6N February 2, 2017 1 / 24 Matrix Consider an m n matrix

More information

Matrix Arithmetic. a 11 a. A + B = + a m1 a mn. + b. a 11 + b 11 a 1n + b 1n = a m1. b m1 b mn. and scalar multiplication for matrices via.

Matrix Arithmetic. a 11 a. A + B = + a m1 a mn. + b. a 11 + b 11 a 1n + b 1n = a m1. b m1 b mn. and scalar multiplication for matrices via. Matrix Arithmetic There is an arithmetic for matrices that can be viewed as extending the arithmetic we have developed for vectors to the more general setting of rectangular arrays: if A and B are m n

More information

1.1 Administrative Stuff

1.1 Administrative Stuff 601.433 / 601.633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Introduction, Karatsuba/Strassen Date: 9/4/18 1.1 Administrative Stuff Welcome to Algorithms! In this class you will learn the

More information

Mathematics Course 111: Algebra I Part I: Algebraic Structures, Sets and Permutations

Mathematics Course 111: Algebra I Part I: Algebraic Structures, Sets and Permutations Mathematics Course 111: Algebra I Part I: Algebraic Structures, Sets and Permutations D. R. Wilkins Academic Year 1996-7 1 Number Systems and Matrix Algebra Integers The whole numbers 0, ±1, ±2, ±3, ±4,...

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

CS 4424 GCD, XGCD

CS 4424 GCD, XGCD CS 4424 GCD, XGCD eschost@uwo.ca GCD of polynomials First definition Let A and B be in k[x]. k[x] is the ring of polynomials with coefficients in k A Greatest Common Divisor of A and B is a polynomial

More information

1 The distributive law

1 The distributive law THINGS TO KNOW BEFORE GOING INTO DISCRETE MATHEMATICS The distributive law The distributive law is this: a(b + c) = ab + bc This can be generalized to any number of terms between parenthesis; for instance:

More information

Advanced Counting Techniques. Chapter 8

Advanced Counting Techniques. Chapter 8 Advanced Counting Techniques Chapter 8 Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence Relations Nonhomogeneous Recurrence Relations Divide-and-Conquer

More information

Answer the following questions: Q1: ( 15 points) : A) Choose the correct answer of the following questions: نموذج اإلجابة

Answer the following questions: Q1: ( 15 points) : A) Choose the correct answer of the following questions: نموذج اإلجابة Benha University Final Exam Class: 3 rd Year Students Subject: Design and analysis of Algorithms Faculty of Computers & Informatics Date: 10/1/2017 Time: 3 hours Examiner: Dr. El-Sayed Badr Answer the

More information

4.4 Recurrences and Big-O

4.4 Recurrences and Big-O 4.4. RECURRENCES AND BIG-O 91 4.4 Recurrences and Big-O In this section, we will extend our knowledge of recurrences, showing how to solve recurrences with big-o s in them, recurrences in which n b k,

More information

14.1 Finding frequent elements in stream

14.1 Finding frequent elements in stream Chapter 14 Streaming Data Model 14.1 Finding frequent elements in stream A very useful statistics for many applications is to keep track of elements that occur more frequently. It can come in many flavours

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Spring 2017-2018 Outline 1 Sorting Algorithms (contd.) Outline Sorting Algorithms (contd.) 1 Sorting Algorithms (contd.) Analysis of Quicksort Time to sort array of length

More information

Follow links for Class Use and other Permissions. For more information send to:

Follow links for Class Use and other Permissions. For more information send  to: COPYRIGHT NOTICE: John J. Watkins: Topics in Commutative Ring Theory is published by Princeton University Press and copyrighted, 2007, by Princeton University Press. All rights reserved. No part of this

More information

feb abhi shelat FFT,Median

feb abhi shelat FFT,Median L8 feb 16 2016 abhi shelat FFT,Median merge-sort (A, p, r) if pn B[k] A[i];

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

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers ALGEBRA CHRISTIAN REMLING 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers by Z = {..., 2, 1, 0, 1,...}. Given a, b Z, we write a b if b = ac for some

More information

Integer Multiplication

Integer Multiplication Integer Multiplication in almost linear time Martin Fürer CSE 588 Department of Computer Science and Engineering Pennsylvania State University 1/24/08 Karatsuba algebraic Split each of the two factors

More information

MATRIX MULTIPLICATION AND INVERSION

MATRIX MULTIPLICATION AND INVERSION MATRIX MULTIPLICATION AND INVERSION MATH 196, SECTION 57 (VIPUL NAIK) Corresponding material in the book: Sections 2.3 and 2.4. Executive summary Note: The summary does not include some material from the

More information

Generating Functions

Generating Functions Generating Functions Karen Ge May, 07 Abstract Generating functions gives us a global perspective when we need to study a local property. We define generating functions and present its applications in

More information

Linear Algebra: Lecture notes from Kolman and Hill 9th edition.

Linear Algebra: Lecture notes from Kolman and Hill 9th edition. Linear Algebra: Lecture notes from Kolman and Hill 9th edition Taylan Şengül March 20, 2019 Please let me know of any mistakes in these notes Contents Week 1 1 11 Systems of Linear Equations 1 12 Matrices

More information

Chapter 4. Matrices and Matrix Rings

Chapter 4. Matrices and Matrix Rings Chapter 4 Matrices and Matrix Rings We first consider matrices in full generality, i.e., over an arbitrary ring R. However, after the first few pages, it will be assumed that R is commutative. The topics,

More information

1 Maintaining a Dictionary

1 Maintaining a Dictionary 15-451/651: Design & Analysis of Algorithms February 1, 2016 Lecture #7: Hashing last changed: January 29, 2016 Hashing is a great practical tool, with an interesting and subtle theory too. In addition

More information

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d CS161, Lecture 4 Median, Selection, and the Substitution Method Scribe: Albert Chen and Juliana Cook (2015), Sam Kim (2016), Gregory Valiant (2017) Date: January 23, 2017 1 Introduction Last lecture, we

More information

DIHEDRAL GROUPS II KEITH CONRAD

DIHEDRAL GROUPS II KEITH CONRAD DIHEDRAL GROUPS II KEITH CONRAD We will characterize dihedral groups in terms of generators and relations, and describe the subgroups of D n, including the normal subgroups. We will also introduce an infinite

More information