Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

Size: px
Start display at page:

Download "Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai"

Transcription

1 Divide-and-Conquer Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

2 Divide and Conquer Given an instance x of a prolem, the method works as follows: divide-and-conquer function DAC( x) if x is sufficiently small then solve it directly else divide x into smaller suinstances x, x,, x ; y DAC( x ), for 1 i k; i ( ) y comine y, y,, y ; return() y i 1 2 k 1 2 k 2

3 Analysis of Divide-and-Conquer Typically, x1,, xk are of the same size, say n. In that case, the time complexity of DAC, Tn ( ), satisfies a recurrence: Tn ( ) = c if n n kt ( n ) + f( n) if n> n0 0 Where f( n) is the running time of dividing x and comining yi's. What is c? What is n? 0 3

4 Mergesort: procedure ( Ai j ) mergesort [.. ] // Sort Ai [.. j]// if i = j then return m ( i+ j)2 mergesort [.. ] Sort an array A[1.. n] ( Ai m) ( Am+ 1.. j] ) ( Ai m Am+ j ) mergesort [ merge [.. ], [ 1.. ] Initial call: mergesort [ ( A1.. n] ) // ase case // divide and conquer 4

5 Analysis of Mergesort Let Tn ( ) denote the running time of mergesorting an array of size n. Tn ( ) satisfies the recurrence: Tn ( ) = c if n 1 ( ) ( ) T n 2 + T n 2 +Θ ( n) if n> 1 Solving the recurrence yields: Tn ( ) = Θ( nlog n) We will learn how to solve such recurrences. 5

6 Linked-List Version of Mergesort function mergesort, ( i j) // Sort A[ i.. j]. Initially, link[ k] = 0, 1 k n.// gloal A[1.. n], link[1.. n] if i = j then retu rn () i // ase case // m ( i+ j)2 ptr1 mergesort ( i, m) ptr2 mergesort ( m + 1, j) divide and conquer ptr merge( ptr1, ptr2) return ( ptr) 6

7 Solving Recurrences Suppose a function T( n) satisfies the recurrence T( n) = c if n 1 ( ) 3T n 4 + n if n> 1 where c is a positive constant. ( ) Wish to otain a function gn ( ) such that Tn ( ) = Θ g(). n Will solve it using various methods: Iteration Method, Recurrence Tree, Guess and Prove, and Master Method. 7

8 Iteration Method m Assume n is a power of 4. Say, n= 4. Then, Tn ( ) = n+ 3 Tn ( / 4) [ ] = n+ 3 n/ Tn ( /16) [ ] = n+ 3( n/ 4) + 9 ( n/16) + 3 Tn ( / 64) = n+ (3/4) n+ (3/4) n+ 3 Tn ( /4 ) 2 m m n = n T m = nθ (1) + On ( ) = Θ( n) So, Tn ( ) =Θ ( nn a power of 4) Tn ( ) =Θ( n). (Why?) 8

9 Remark We have applied Theorem 7 to conclude Tn ( ) = Θ( n) from Tn ( ) = Θ( nn a power of 4). In order to apply Theorem 7, Tn ( ) needs to e nondecreasing. It will e a homework question for you to prove that Tn ( ) is indeed nondecreasing. 9

10 Recurrence Tree solving prolems 1 of size n 3 of size n / 4 3 of size n / of size n / m 1 3 of si n ze n / 4 3 of size n / 4 m 1 time needed 3 n /4 3 n / /4 n 3 m 1 3 / m m m n 4 Θ(1) m 1 10

11 Guess and Prove Solve Tn ( ) = c if n 1 ( ) 3T n 4 +Θ ( n) if n> 1 First, guess Tn ( ) = Θ( n), and then try to prove it. m Sufficient to consider n= 4, m= 0, 1, 2,... Need to prove: c 4 T(4 ) c 4 m m 1 2 and all m m for some m. We choose m = 0 y induction on m. IB: When m= 0, c 4 T(4 ) c 4 m f or i f c some c, c IH: Assume c 4 T(4 ) c 4 for some c, c and prove m 1 m 1 m c c.. 11

12 m m 1 m IS: T(4 ) = 3 T(4 ) +Θ(4 ) T m 3c 4 + c 4 for some constant c m ( c c ) = c 2 T m if m m 1 m (4 ) = 3 (4 ) (4 ) 1 2 m c c +Θ 3c m 1 1 c 1 ( c c ) = m c1 4 if c 1 c1 4 Let c, c e such that c c c, c c 4, c 4 c. Then, c m m m m m 14 T ( 4 ) c2 4 for all m 0. 4 for some constant 1 2 c 12

13 The Master Theorem Definition: f( n) is polynomially smaller than gn ( ), denoted ε ε as f( n) gn ( ), iff f( n) = Ognn ( ( ) ), or f( nn ) = Ogn ( ( )), for some ε > For example, 1 n n n n. Is 1 log n? Or n nlog n? To answer these, ask yourself whether or not n ε = O(log n). ( ) For convenience, write f( n) gn ( ) iff f( n) =Θ gn ( ). Note: the notations and are good only for this class. 13

14 The Master Theorem If T( n) satisfies the recurrence T( n) = at( n/ ) + f( n), then T( n) is ounded asymptotically as follows. 1. ( log ) a loga If ( ), then ( ). f n n T n = Θ n log a 2. If ( ), then ( ) ( ) f n n T n = Θ f n ( ) ( ) ( ) log a If ( ), then ( ) ( )log. f n n T n =Θ f n n log a k If ( ) log, then ( ) ( )log. f n n n T n =Θ f n n In case 2, it is required that af( n/ ) cf( n) for some c< 1, which is satisfied y most f( n) that we shall encounter. In the theorem, n/ should e interpreted as n/ or n/. 14

15 Examples: solve these recurrences Tn ( ) = 3 Tn ( / 4) + n. Tn ( ) = 9 Tn ( / 3) + n. Tn ( ) = T(2 n/ 3) + 1. Tn ( ) = 3 Tn ( / 4) + nlog n. Tn = Tn + Θ n 2 ( ) 7 ( / 2) ( ). Tn ( ) = 2 Tn ( / 2) + nlog n. Tn ( ) = Tn ( / 3) + T(2 n/ 3) + n. 15

16 Tn ( ) = atn ( / ) + fn ( ) a solving prolems time needed 2 log n 1 a log 1 of size n f( n) a of size n / a n of size n/ of size n/ of size n / 2 log n 1 log a 2 log n 1 a f( n/ ) a f( n/ f( n/ n log a n Θ (1) 2 ) log n 1 ) 16

17 Tn ( ) = atn ( / ) + fn ( ) 1 of size n a of size n/ a 2 log n 1 a a log n of size n/ of size n / of size n/ 2 log n 1 log n a 2 log n 1 f( n) a f( n/ ) a a log f( n/ f ( n / n 2 Θ(1) ) log n 1 ) Tn ( ) log n 1 i i log a a af( n/ ) + n (Note: logn= = logan log a) i= 0 loga = log n 17

18 Suppose f ( n) = Θ ( log ) a n. log ( ) ( ) loga loga i i n n Then f n / = Θ n/ = Θ =, i log a Θ i a ( ) ( log ) i a = Θ n i and thus af n/. Then, we have a Tn ( ) log n 1 = i= 0 a i i ( ) f n + log a / n (from the previous slide) log n 1 log a log a log a = = i= 0 = Θ ( log n) Θ( ( ) log n) n + n Θ n f n 18

19 When recurrences involve roots ( ) 2T n + log n if n> 2 Solve Tn ( ) = c otherwise m Suffices to consider only powers of 2. Let n = 2. m Define a new function Sm ( ) = T(2 ) = Tn ( ). The aove recurrence translates to ( ) 2 S m/ 2 + m if m> 1 Sm ( ) = c otherwise By Master Theorem, Sm ( ) = Θ( mlog m). So, Tn ( ) = Θ(log nlog log n) 19

20 Strassen's Algorithm for Matrix Multiplication Prolem: Compute C = AB, given n n matrices A and B. The straightforward method requires Θ( n using the formula c = a. n ij ik kj k = 1 log matrices in On ( ) = On ( ) time. 3 ) time, Toward the end of 1960s, Strassen showed how to multiply For n= 100, n 416,869, and n = 1, 000, The time complexity was reduced to On ( ) in 1979, to On ( ) in 1980, and to On ( ) in In the following discussion, n is assumed to e a power of 2. 20

21 Write A11 A12 B11 B12 C11 C12 A=, B, C A A = = B B C C where each A, B, C is a n/ 2 n/ 2 matrix. ij ij ij Then C C A A B B C C = A A B B If we compute C = AB + AB, the running time Tn ( ) ij i1 1j i2 2 j 2 will satisfy the recurrence T( n) = 8 T( n/ 2) +Θ( n ) T n 3 ( ) will e Θ( ), not etter than the straightforward one. n Good for parallel processing. What's the running time using Θ( n 3 ) processors? 21

22 Strassen showed C C C21 C = 22 M1 + M2 + M4 M7 M1 + M2 + M4 + M 5 where M = ( A + A A ) ( B B + B ) M = A B M = A B M M + M M + M + M + M = ( A A ) ( B B ) M = ( A + A ) ( B B ) M = ( A A + A A ) B M = A ( B + B B B ) T( n) = 7 T( n / +Θ n T( n) = Θ( n 2 log7 2) ( ) ) 22

23 The Closest Pair Prolem Prolem Statement: Given a set of { } n points in the plane, A= ( x, y ) : 1 i n, find two points in A whose i i distance is smallest among all pairs. Straightforward method: Θ 2 ( n ). Divide and conquer: On ( log n). 23

24 The Divide-and-Conquer Approach 1. Partition A into two sets: A= B C. 2. Find a closest pair ( p, q ) in B Find a closest pair ( p, q ) in C. 2 2 { p q p q } 4. Let δ = min dist(, ), dist(, ) Find a closest pair ( p, q ) etween B and C with 3 3 distance less than δ, if such a pair exists. 6. Return the pair of the three which is closest. Question : What would e the running time? Desired: T ( n) = 2 Tn ( /2) + On ( ) Tn ( ) = On ( log n). 24

25 Now let's see how to implement each step. Trivial: steps 2, 3, 4, 6. 25

26 Step 1: A A B C Partition into two sets: =. A natural choice is to draw a vertical line to divide the points into two groups. So, sort A[1.. n] y x-coordina te. (Do this Then, we can easily partition any set Ai [.. j] y Ai [.. j] = Ai [.. m] Am [ j] where m= ( i+ j) 2. only onc e.) 26

27 Step 5: Find a closest pair etween B and C with distance less than δ, if exists. We will write a procedure Closest-Pair-Between-Two-Sets ( ) ( A[ i.. j], ptr, δ, ( p3, q3) ) which finds a closest pair etween Ai [.. m] and Am [ j] with distance less than δ, if exists. The running time of this procedure must e no more than ( ) O Ai [.. j] in order for the final algorithm to e O nlog n. 27

28 Data Structures Let the coordinates of the n points e stored in X[1.. n] and Y[1.. n]. For simplicity, let Ai [ ] = ( X[ i], Y[ i]). For convenience, introduce two dummy points: A[0] = (, ) and An [ + 1] = (, ) We will use these two points to indicate "no pair" or "no pair closer than δ." Introduce an array Link[1.. n], initialized to all 0's. 28

29 Main Program Gloal variale: A[0.. n+ 1] Sort A[1.. n] such that X[1] X[2] Xn [ ]. That is, sort the given n points y x-coordinate. Call Procedure Closest-Pair with appropriate parameters. 29

30 {*returns a closest pair ( p, q) in Ai [.. j]*} If j i = 0: ( p, q) (0, n+ 1); If j i = 1: ( p, q) ( i, j); If j i > 1: m ( i+ j) 2 Closest-Pair Ai [.. m], ( p, q) ( Ai j p q ) //Version 1// Procedure Closest-Pair [.. ], (, ) ( 1 1 ) ( Am+ j p q ) Closest-Pair [ 1.. ], (, ) 2 2 ptr mergesort A[ i.. j] y y-coordinate into a linked list δ { p1 q1 p2 q2 } ( Ai j ptr, δ, ( p, q )) min dist(, ), dist(, ) Closest-Pair-Between-Two-Sets [.. ], 3 3 ( p, q) closest of the three ( p, q ), ( p, q ), ( p, q )

31 Time Complexity of version 1 ( A n p q ) Initial call: Closest-Pair [1.. ], (, ). Assume Closest-Pair-Between-Two-Sets needs Θ( n) time. Let Tn ( ) denote the worst-case running time of Closest-Pair A[1.. n], ( p, q). ( ) Then, Tn ( ) = 2 Tn ( / 2) +Θ( nlog n). ( 2 ) So, Tn ( ) = Θ nlog n. Not as good as desi red. 31

32 How to reduce the time complexity to On ( log n)? Suppose we use Mergesort to sort Ai [.. j]: ptr Sort A[ i.. j] y y-coordinate into Rewrite the procedure as version 2. a linked list We only have to sort the ase cases and perform "merge." Here we take a free ride on Closest-Pair for dividing. That is, we comine Mergesort with Closest-Pai r. 32

33 If j i = 0: ( p, q) (0, n+ 1); If j i = 1: ( p, q) ( i, j); If j i > 1: m ( i+ j) 2 Closest-Pair [.. ], (, Closest-Pair [ 1.. ( Ai j p q ) Procedure Closest-Pair [.. ], (, ) ( A im p1 q1) ) ( Am+ j], ( p2, q2) ) t ( A[ i.. m] ) ( A m + j] ) ( ptr ptr ) //Version ptr1 Mergesor ptr2 Mergesort [ 1.. mergesort [.. j] ptr Merge 1, 2 (the rest is the same as in version 1) ( Ai ) 2 // 33

34 ( A i j p q ptr) Procedure Closest-Pair [.. ], (, ), {* mergesort Ai [.. j] y y and find a closest pair ( p, q) in if j i = 0: ( p, q) (0, n + 1); ptr i if j i = 1: ( p, q) ( i, j); //final version// { } { ptr j Link j i} if Y[ i] Y[ j] then ptr i; Link[] i j else ; [ ] if j i > 1: m ( i+ j) 2 Closest-Pair Ai [.. m], ( p, q ), ptr1 ( 1 1 ) ( A m + j p2 q2 ptr ) ( ) Closest-Pair [ 1.. ], (, ), 2 ptr Merge ptr1, ptr2 (the rest is the same as in version 1) Ai [.. j] *} 34

35 Time Complexity of the final version ( A n p q pqr) Initial call: Closest-Pair [1.. ], (, ),. Assume Closest-Pair-Between-Two-Sets needs Θ( n) time. Let Tn ( ) denote the worst-case running time ( ) Closest-Pair A[1.. n], ( p, q), pqr. of Then, Tn ( ) = 2 Tn ( / 2) +Θ( n). ( ) So, Tn ( ) = Θ nlog n. Now, it remains to write the procedure Closest-Pair-Between-Two-Sets [.. ],,, (, ) ( A i j ptr δ p q )

36 Closest-Pair-Between-Two-Sets ( A i j ptr δ ) Input: [.. ],, Output: a closest pair ( p, q) etween B= Ai [.. m] and C= Am [ j] with distance < δ, where m= ( i+ j) / 2. If there is no such a pair, return the dummy pair (0, n + 1). ( Ai j ) Time complexity desired : O [.. ]. For each point B, we will compute dist( c, ) for O(1) points c C. Similarly for each point c C. Recall that Ai [.. j] has sorted linked list and look at each point. een sorted y y. We will follow the 36

37 Closest-Pair-Between-Two-Sets L0: vertical line passing through the point Am [ ]. L1 and L2: vertical lines to the left and right of L0 y δ. We oserve that: We only need to consider thos e points etween L1 and L2. For each point kin Ai [.. m], we only need to consider the points in Am [ j] that are inside the square of δ δ. There are at most three such points. And they are among the most recently visited three points of Am [ j] lying etween L0 and L2. Similar argument for each point kin Am [ j]. 37

38 L 1 L 0 L 2 k Red points are apart y at least δ δ δ Blue points are apart y at least δ For k, only need to consider the points in the square less the right and ottom edges 38

39 Closest-Pair-Between-T wo-sets( A[ i.. j], ptr, δ, ( p, 3 3 // Find the closest pair etween Ai [.. m] and Am [ j] with dist < δ. If there exists no such a pair, then return the dummy pair ( 0, n + 1). // gloal 3 3 X[0.. n+ 1], Y [0.. n+ 1], Link[1.. n] ( p, q ) (0, n+ 1),, 0 //most recently visited 3 points twn L, L // c, c, c n+ 1 //such points etween L, L // m ( i+ j)2 k ptr q )) 39

40 while k 0 do //follow the linked list until end// 1. if X[ k] X[ m] < δ then if k m then //point k is to the left of // consider only twn L, L // compute d min{dist( k, c ) : 1 i 3}; if d < δ then update δ and ( p, q ); ; ; k; else //point k is to the right of L // 2. k Link[ k] compute d min{ dist( k, ) : 1 i 3}; if d < δ then update δ and ( p, q ); c c ; c c; c k; i i 3 3 L 0 //

41 Convex Hull Prolem Statement: Given a set of { } say, A= p, p, p,, p, we want to find the convex hull of A. The convex hull of A, denoted y CH ( A), convex polygon that encloses all points of A. n n points in the plane, is the smallest Oservation: segment pip j is an edge of CH ( A) if all other points of Aare on the same side of pp (or on pp). 2 Straightforward method: Ω( n ). Divide and conquer: On ( log n). i j i j 41

42 Divide-and-Conquer for Convex Hull 0. Assume all x-coordinates are different, and no three points are colinear. (Will e removed later.) 1. Let A e sorted y x-coordinate. 2. If A 3, solve the prolem directly. Otherwise, apply divide-and-conquer as follows. 3. Break up A into A= B C. 4. Find the convex hull of B. 5. Find the convex hull of C. 6. Comine the two convex hulls y finding the upper and lower ridges to connect the two convex hulls. 42

43 Upper and Lower Bridges The upper ridge etween CH ( B) and CH ( C) is the the edge vw, where v CH ( B) and w CH ( C), such that all other vertices in CH ( B) and CH ( C) are elow vw, or the two neighors of v in CH ( B) and the two neighors of w in CH ( C) are elow vw, or the counterclockwise-neighor of v in CH ( B) and the clockwise-neighor of w in CH ( C) are elow vw, if v and w Lower ridge: simil ar. are chosen as in the next slide. 43

44 Finding the upper ridge v the rightmost point in CH ( B); w Loop vw the leftmost point in CH ( C). if counterclockwise-neighor( v) lies aove line v counterclockwise-neighor( v) else if clockwise-neighor( w) lies aove w clockwise neighor( w) else exit from the loop is the upper ridge. vw then vw then 44

45 Data Structure and Time Complexity What data structure will you use to represent a convex hull? Using your data structure, how much time will it take to find the upper and lower ridges? What is the over all running time of the algorithm? We assumed: (1) no two points in A share the same x-coordinate (2) no three points in A are colinear Now let's remove these assumptions. 45

46 Orientation of three points ( ) ( ) ( ) Three points: p x, y, p x, y, p x, y ( p, p, p ) in that order is counterclockwise if x x x y 1 1 y 2 2 y > 0 1 Clockwise if the determinant is negative. Colinear if the determinant is zero. 46

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

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count Types of formulas for basic operation count Exact formula e.g., C(n) = n(n-1)/2 Algorithms, Design and Analysis Big-Oh analysis, Brute Force, Divide and conquer intro Formula indicating order of growth

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

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

Divide and Conquer Strategy

Divide and Conquer Strategy Divide and Conquer Strategy Algorithm design is more an art, less so a science. There are a few useful strategies, but no guarantee to succeed. We will discuss: Divide and Conquer, Greedy, Dynamic Programming.

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

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

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

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

CPS 616 DIVIDE-AND-CONQUER 6-1

CPS 616 DIVIDE-AND-CONQUER 6-1 CPS 616 DIVIDE-AND-CONQUER 6-1 DIVIDE-AND-CONQUER Approach 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger)

More information

Recommended readings: Description of Quicksort in my notes, Ch7 of your CLRS text.

Recommended readings: Description of Quicksort in my notes, Ch7 of your CLRS text. Chapter 1 Quicksort 1.1 Prerequisites You need to be familiar with the divide-and-conquer paradigm, standard notations for expressing the time-complexity of an algorithm, like the big-oh, big-omega notations.

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

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2 1 Faculty of Mathematics Waterloo, Ontario Centre for Education in Mathematics and Computing Grade 11/12 Math Circles Fall 2014 - Nov. 5 Recurrences, Part 2 Running time of algorithms In computer science,

More information

Analysis of Algorithms - Using Asymptotic Bounds -

Analysis of Algorithms - Using Asymptotic Bounds - Analysis of Algorithms - Using Asymptotic Bounds - Andreas Ermedahl MRTC (Mälardalens Real-Time Research Center) andreas.ermedahl@mdh.se Autumn 004 Rehersal: Asymptotic bounds Gives running time bounds

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

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

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

Divide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014

Divide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 Divide&Conquer: MergeSort Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 1 Divide-and-Conquer Algorithms Divide-and-conquer algorithms work according to the

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 10, 2018 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. 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

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 4 - Jan. 14, 2019 CLRS 1.1, 1.2, 2.2, 3.1, 4.3, 4.5 University of Manitoba Picture is from the cover of the textbook CLRS. COMP

More information

Asymptotic Analysis and Recurrences

Asymptotic Analysis and Recurrences Appendix A Asymptotic Analysis and Recurrences A.1 Overview We discuss the notion of asymptotic analysis and introduce O, Ω, Θ, and o notation. We then turn to the topic of recurrences, discussing several

More information

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation:

Data structures Exercise 1 solution. Question 1. Let s start by writing all the functions in big O notation: Data structures Exercise 1 solution Question 1 Let s start by writing all the functions in big O notation: f 1 (n) = 2017 = O(1), f 2 (n) = 2 log 2 n = O(n 2 ), f 3 (n) = 2 n = O(2 n ), f 4 (n) = 1 = O

More information

1 Substitution method

1 Substitution method Recurrence Relations we have discussed asymptotic analysis of algorithms and various properties associated with asymptotic notation. As many algorithms are recursive in nature, it is natural to analyze

More information

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture 1: Asymptotics, Recurrences, Elementary Sorting Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

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

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University)

CIS 121. Analysis of Algorithms & Computational Complexity. Slides based on materials provided by Mary Wootters (Stanford University) CIS 121 Analysis of Algorithms & Computational Complexity Slides based on materials provided by Mary Wootters (Stanford University) Today Sorting: InsertionSort vs MergeSort Analyzing the correctness of

More information

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

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

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

Algorithms Design & Analysis. Analysis of Algorithm

Algorithms Design & Analysis. Analysis of Algorithm Algorithms Design & Analysis Analysis of Algorithm Review Internship Stable Matching Algorithm 2 Outline Time complexity Computation model Asymptotic notions Recurrence Master theorem 3 The problem of

More information

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013 /4/3 Administrative Big O David Kauchak cs3 Spring 3 l Assignment : how d it go? l Assignment : out soon l CLRS code? l Videos Insertion-sort Insertion-sort Does it terminate? /4/3 Insertion-sort Loop

More information

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n Fundamental Algorithms Homework #1 Set on June 25, 2009 Due on July 2, 2009 Problem 1. [15 pts] Analyze the worst-case time complexity of the following algorithms,and give tight bounds using the Theta

More information

Recurrence Relations

Recurrence Relations Recurrence Relations Analysis Tools S.V. N. (vishy) Vishwanathan University of California, Santa Cruz vishy@ucsc.edu January 15, 2016 S.V. N. Vishwanathan (UCSC) CMPS101 1 / 29 Recurrences Outline 1 Recurrences

More information

CS 161 Summer 2009 Homework #2 Sample Solutions

CS 161 Summer 2009 Homework #2 Sample Solutions CS 161 Summer 2009 Homework #2 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than

More information

Methods for solving recurrences

Methods for solving recurrences Methods for solving recurrences Analyzing the complexity of mergesort The merge function Consider the following implementation: 1 int merge ( int v1, int n1, int v, int n ) { 3 int r = malloc ( ( n1+n

More information

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide

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

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

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali March 17, 2014 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine solutions

More information

Algorithms And Programming I. Lecture 5 Quicksort

Algorithms And Programming I. Lecture 5 Quicksort Algorithms And Programming I Lecture 5 Quicksort Quick Sort Partition set into two using randomly chosen pivot 88 31 25 52 14 98 62 30 23 79 14 31 2530 23 52 88 62 98 79 Quick Sort 14 31 2530 23 52 88

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

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

Data Structures and Algorithms CSE 465

Data Structures and Algorithms CSE 465 Data Structures and Algorithms CSE 465 LECTURE 3 Asymptotic Notation O-, Ω-, Θ-, o-, ω-notation Divide and Conquer Merge Sort Binary Search Sofya Raskhodnikova and Adam Smith /5/0 Review Questions If input

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms. Solving recurrences Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms Example: Merge-Sort(A, p, r) 1: if p < r then 2: q (p + r)/2 3: Merge-Sort(A,

More information

The Divide-and-Conquer Design Paradigm

The Divide-and-Conquer Design Paradigm CS473- Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm CS473 Lecture 4 1 The Divide-and-Conquer Design Paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems

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

Mergesort and Recurrences (CLRS 2.3, 4.4)

Mergesort and Recurrences (CLRS 2.3, 4.4) Mergesort and Recurrences (CLRS 2.3, 4.4) We saw a couple of O(n 2 ) algorithms for sorting. Today we ll see a different approach that runs in O(n lg n) and uses one of the most powerful techniques for

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 1 Data Structures and Algorithms Chapter 3 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

CS 231: Algorithmic Problem Solving

CS 231: Algorithmic Problem Solving CS 231: Algorithmic Problem Solving Naomi Nishimura Module 4 Date of this version: June 11, 2018 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides

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

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

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee Algorithm Analysis Recurrence Relation Chung-Ang University, Jaesung Lee Recursion 2 Recursion 3 Recursion in Real-world Fibonacci sequence = + Initial conditions: = 0 and = 1. = + = + = + 0, 1, 1, 2,

More information

Divide-and-conquer. Curs 2015

Divide-and-conquer. Curs 2015 Divide-and-conquer Curs 2015 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers. Known Examples: Binary

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 2.1 Notes Homework 1 will be released today, and is due a week from today by the beginning

More information

Divide-and-Conquer Algorithms Part Two

Divide-and-Conquer Algorithms Part Two Divide-and-Conquer Algorithms Part Two Recap from Last Time Divide-and-Conquer Algorithms A divide-and-conquer algorithm is one that works as follows: (Divide) Split the input apart into multiple smaller

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

Analysis of Algorithms

Analysis of Algorithms September 29, 2017 Analysis of Algorithms CS 141, Fall 2017 1 Analysis of Algorithms: Issues Correctness/Optimality Running time ( time complexity ) Memory requirements ( space complexity ) Power I/O utilization

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 & 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

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

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

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

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

COMP 382: Reasoning about algorithms

COMP 382: Reasoning about algorithms Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For

More information

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0

Asymptotic Notation. such that t(n) cf(n) for all n n 0. for some positive real constant c and integer threshold n 0 Asymptotic Notation Asymptotic notation deals with the behaviour of a function in the limit, that is, for sufficiently large values of its parameter. Often, when analysing the run time of an algorithm,

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali February 19, 2013 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine

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

Algorithms. Quicksort. Slide credit: David Luebke (Virginia)

Algorithms. Quicksort. Slide credit: David Luebke (Virginia) 1 Algorithms Quicksort Slide credit: David Luebke (Virginia) Sorting revisited We have seen algorithms for sorting: INSERTION-SORT, MERGESORT More generally: given a sequence of items Each item has a characteristic

More information

LECTURE NOTES ON DESIGN AND ANALYSIS OF ALGORITHMS

LECTURE NOTES ON DESIGN AND ANALYSIS OF ALGORITHMS G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY LECTURE NOTES ON DESIGN AND ANALYSIS OF ALGORITHMS Department of Computer Science and Engineering 1 UNIT 1 Basic Concepts Algorithm An Algorithm is a finite

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

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

Analysis of Multithreaded Algorithms

Analysis of Multithreaded Algorithms Analysis of Multithreaded Algorithms Marc Moreno Maza University of Western Ontario, London, Ontario (Canada) CS 4435 - CS 9624 (Moreno Maza) Analysis of Multithreaded Algorithms CS 4435 - CS 9624 1 /

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Algorithm Analysis 1 Purpose Why bother analyzing code; isn t getting it to work enough? Estimate time and memory in the average case and worst case Identify bottlenecks, i.e., where to reduce time Compare

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

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

COMP 355 Advanced Algorithms

COMP 355 Advanced Algorithms COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background 1 Polynomial Running Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that

More information

Divide and Conquer. Recurrence Relations

Divide and Conquer. Recurrence Relations Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.

More information

Homework 1 Submission

Homework 1 Submission Homework Submission Sample Solution; Due Date: Thursday, May 4, :59 pm Directions: Your solutions should be typed and submitted as a single pdf on Gradescope by the due date. L A TEX is preferred but not

More information

Lecture 4. Quicksort

Lecture 4. Quicksort Lecture 4. Quicksort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018 Networking

More information

Algorithm efficiency analysis

Algorithm efficiency analysis Algorithm efficiency analysis Mădălina Răschip, Cristian Gaţu Faculty of Computer Science Alexandru Ioan Cuza University of Iaşi, Romania DS 2017/2018 Content Algorithm efficiency analysis Recursive function

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

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer. Department of Computer Science Virginia Tech Blacksburg, Virginia Copyright c 2010,2017 by Clifford A. Shaffer Data and Algorithm Analysis Title page Data and Algorithm Analysis Clifford A. Shaffer Spring

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

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University CS 5321: Advanced Algorithms - Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating example:

More information

Solving Recurrences. Lecture 23 CS2110 Fall 2011

Solving Recurrences. Lecture 23 CS2110 Fall 2011 Solving Recurrences Lecture 23 CS2110 Fall 2011 1 Announcements Makeup Prelim 2 Monday 11/21 7:30-9pm Upson 5130 Please do not discuss the prelim with your classmates! Quiz 4 next Tuesday in class Topics:

More information

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background 1 Polynomial Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that checks every

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

Divide-Conquer-Glue Algorithms

Divide-Conquer-Glue Algorithms Divide-Conquer-Glue Algorithms Mergesort and Counting Inversions Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 10 Divide-and-conquer. Divide up problem into several subproblems. Solve each subproblem recursively.

More information

Dynamic Programming. Reading: CLRS Chapter 15 & Section CSE 6331: Algorithms Steve Lai

Dynamic Programming. Reading: CLRS Chapter 15 & Section CSE 6331: Algorithms Steve Lai Dynamic Programming Reading: CLRS Chapter 5 & Section 25.2 CSE 633: Algorithms Steve Lai Optimization Problems Problems that can be solved by dynamic programming are typically optimization problems. Optimization

More information

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2 In-Class Soln 1 Let f(n) be an always positive function and let g(n) = f(n) log n. Show that f(n) = o(g(n)) CS 361, Lecture 4 Jared Saia University of New Mexico For any positive constant c, we want to

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

Problem Set 1 Solutions

Problem Set 1 Solutions Introduction to Algorithms September 24, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Piotr Indyk and Charles E. Leiserson Handout 7 Problem Set 1 Solutions Exercise 1-1. Do Exercise

More information

CS 4407 Algorithms Lecture 2: Growth Functions

CS 4407 Algorithms Lecture 2: Growth Functions CS 4407 Algorithms Lecture 2: Growth Functions Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline Growth Functions Mathematical specification of growth functions

More information

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline CS 5321: Advanced Algorithms Analysis Using Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating

More information

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005 V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the

More information

Lecture 3. Big-O notation, more recurrences!!

Lecture 3. Big-O notation, more recurrences!! Lecture 3 Big-O notation, more recurrences!! Announcements! HW1 is posted! (Due Friday) See Piazza for a list of HW clarifications First recitation section was this morning, there s another tomorrow (same

More information