Recurrences 2008. 1. 11 : 1 Chapter 3. Growth of function Chapter 4. Recurrences.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Mathematical Preliminaries
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
2. Getting Started Heejin Park College of Information and Communications Hanyang University.
Introduction to Algorithms
Chapter 1 The Study of Body Function Image PowerPoint
October 17, 2005 Copyright© Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.
Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 2 Prof. Erik Demaine.
© 2001 by Charles E. Leiserson Introduction to AlgorithmsDay 17 L9.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 9 Prof. Charles E. Leiserson.
©2001 by Charles E. Leiserson Introduction to AlgorithmsDay 9 L6.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 6 Prof. Erik Demaine.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Divide-and-Conquer CIS 606 Spring 2010.
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
ABC Technology Project
VOORBLAD.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Divide and Conquer (Merge Sort)
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
25 seconds left…...
Chapter Algorithms 3.2 The Growth of Functions
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Januar MDMDFSSMDMDFSSS
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Mathematics1 Mathematics 1 Applied Informatics Štefan BEREŽNÝ.
PSSA Preparation.
Master Theorem Chen Dan Dong Feb. 19, 2013
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
11 Computer Algorithms Lecture 6 Recurrence Ch. 4 (till Master Theorem) Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Updates HW#1 has been delayed until next MONDAY. There were two errors in the assignment Merge sort runs in Θ(n log n). Insertion sort runs in Θ(n2).
4.Recurrences Hsu, Lih-Hsing. Computer Theory Lab. Chapter 4P.2 Recurrences -- Substitution method Recursion-tree method Master method.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Chapter 4: Solution of recurrence relationships
Analysis of Algorithms
MCA 202: Discrete Mathematics Instructor Neelima Gupta
1 Computer Algorithms Lecture 7 Master Theorem Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Project 2 due … Project 2 due … Project 2 Project 2.
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
Chapter 4. Recurrences. Outline Offers three methods for solving recurrences, that is for obtaining asymptotic bounds on the solution In the substitution.
Divide-and-Conquer UNC Chapel HillZ. Guo. Divide-and-Conquer It’s a technique instead of an algorithm Recursive in structure – Divide the problem into.
Recurrences – II. Comp 122, Spring 2004.
Divide and Conquer. Recall Divide the problem into a number of sub-problems that are smaller instances of the same problem. Conquer the sub-problems by.
1Computer Sciences Department. Objectives Recurrences.  Substitution Method,  Recursion-tree method,  Master method.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences.
Master Method Some of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Recurrences (in color) It continues…. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. When an algorithm.
BY Lecturer: Aisha Dawood. A recurrence is a function is defined in terms of:  one or more base cases, and  itself, with smaller arguments. 2.
Chapter 4: Solution of recurrence relationships Techniques: Substitution: proof by induction Tree analysis: graphical representation Master theorem: Recipe.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Recurrences It continues… Jeff Chastine. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. A recurrence.
Equal costs at all levels
Ch 4: Recurrences Ming-Te Chi
Introduction To Algorithms
Presentation transcript:

Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences

Contents of Table 1.Review 2.Asymptotic notation 3.The substitution method 4.The recursion-tree method 5.The master theorem method 6.Proof of the master theorem 2

1. Review 3 Insertion SortMerge Sort Best, Worst, Average case draw and understandrecursion tree Address logically to audience

Theta[θ]-notation - [Theta] : f(n) = θ(g(n)) - for all n, n n 0, If there exist positive constant c 1, c 2 and n 0 such that c 1 g(n) f(n) c 2 g(n) then, f(n) = θ(g(n)). - if g(n) is both an upper and lower bound on f(n) then, f(n) = g(n) Asymptotic notation

Big Oh[O]-notation - [Big Oh] : f(n) = O(g(n)) - for all n, n n 0, If there exist positive constant c and n 0 such that f(n) c g(n) then, f(n) = O(g(n)) Asymptotic notation

Omega [ Ω ]-notation - [Omega] : f(n) = Ω (g(n)) - for all n, n n 0, If there exist positive constant c and n 0 such that c g(n) f(n) then, f(n) = Ω(g(n)) Asymptotic notation

Recurrences 7 Recurrence - Definition Equation or inequality that describes a function in terms of its value on smaller inputs. - Recurrence Solution Method substitution method recursion-tree method master method if n=1 if n>1

Recurrences Technicalities - Omit Technical Details assumption of integer floors ceilings boundary condition - Example (Merge Sort) if n=1 if n>1 if n=1 if n>1 Assumption of integer Boundary condition Floors and ceilings

3. The substitution method 9 Substitution Method - Two steps - It can be used to establish either upper or lower bounds on a recurrence. 1. Guess the form of the solution 2. Use mathematical induction to find the constant and show that the solution works. 1. Guess the form of the solution 2. Use mathematical induction to find the constant and show that the solution works.

3. The substitution method 10 Example Step for substitution method 1. guess that the solution is 2. prove that ( c >0 ) 1. guess that the solution is 2. prove that ( c >0 )

3. The substitution method 11 - Assume that this bound holds for n/2, that is, T ( n/2 ) c n/2 lg( n/2 ). T(n) 2(c n/2 lg( n/2 )) + n cn lg(n/2) + n ( because, n/2 < n/2 ) = cn lg n - cn lg 2 + n = cn lg n - cn + n cn lg n (as long as c 1 )

3. The substitution method Find the constant n 0 - we can take advantage of asymptotic notation, we can replace base case T(1) cn lg n T(1) = 1 but, c1 lg1 = 0 - So, we only have to prove T (n) = cn lg n for n n 0 for n (n 0 =2) 12 Replace T(1) by T(2) and T(3) as the base cases by letting n 0 =2.

3. The substitution method Find the constant c -choosing c large enough T (2) = 4 and T (3) = 5. T (2) = 4 c 2 lg 2 T (3) = 5 c 3 lg Any choice of c 2 suffices for base case of n n 0, n 0 =2

4. The recursion-tree method Recursion-tree - Definition Each node represents the cost of a single subprogram somewhere in t he set of recursive function invocation - The reason why we use this method A recursion-tree is best used to generate a good guess Use directly to prove the master theorem - Total Cost We sum the cost each level of the tree to obtain a set of per-level costs, and then we sum all the per-level costs to determine the total cost of all levels of the recursion 14

4. The recursion-tree method Example Draw recursion tree 15 cn 2 T(n)T(n) T (n) = 3T ( n/4 ) + Θ(n 2 ) < 3T (n/4) + cn 2 T (n) = 3T ( n/4 ) + Θ(n 2 ) < 3T (n/4) + cn 2

4. The recursion-tree method Recursion-tree 16 cn 2 c(n/4) 2 T(1) … Depth Sub problem size 0 n 1 n/4 2 n/ i n/4 i = 1 log 4 n

4. The recursion-tree method 17 Total Cost - When depth i then subprogram size is n/4 i = 1 so, i = log 4 n and it means trees height and tree has log 4 n + 1 levels. - The number of nodes at depth i is 3 i and finally - Total Cost is Sum of cost for root to i-1 depth Sum of cost for i depth

4. The recursion-tree method 18 Total Cost is..

4. The recursion-tree method 19 Prove T (n) = O(n 2 ) by the substitution method - Problem - Step for substitution method T (n) = 3T ( n/4 ) + Θ(n 2 ) 1. guess that the solution is T (n) = O(n 2 ) 2. prove that T (n) dn 2 (for some d > 0 and for the same c > 0 ) 1. guess that the solution is T (n) = O(n 2 ) 2. prove that T (n) dn 2 (for some d > 0 and for the same c > 0 )

4. The recursion-tree method 20 Prove.. Find constant d T(n) 3T( n/4 ) + cn 2 3d n/4 2 + cn 2 3d(n/4) 2 + cn 2 = 3/16 dn 2 + cn 2 dn 2 ( where the last step holds as long as d (16/13)c )

5. The master theorem method Master theorem - Definition method for solving recurrences of the form where a 1 and b > 1 ar e constant and f (n) is an asymptotically positive function 21 The cost of dividing the program and combining Subprograms are solved recursively

5. The master theorem method Master theorem 22 if n=1 if n>1 By Assumption of integer and Boundary condition By Draw recursion tree

5. The master theorem method 23 Three case of master theorem The three case of master theorem correspond to cases in which th e total cost of the tree. - Case 1 : dominated by the costs in the leaves. < - Case 2 : distributed across the levels of the tree. = - Case 3 : dominated by the cost of the root. >

5. The master theorem method Master theorem 24 Let a 1 and b > 1 are constants, let f (n) be a function, and let T (n) be defined on the nonnegative integers by the recurrence where we interpret n/b to mean either or. Then T (n) can be bounded asymptotically as follows. 1. If for some constant ε > 0, then. 2. If, then. 3. If for some constant ε > 0, and if af (n/b) cf (n) for some constant c < 1 and all sufficiently large n, then.

5. The master theorem method 25 Exception in case of master theorem - Exception A : Gap between cases 1 and 2 when < but not polynomially smaller. - Exception B : Gap between cases 2 and 3 when > but not polynomially larger.

5. The master theorem method 26 Exception in case of master theorem a=2, b=2, f (n) = n lg n, and it might be case 3? Asymptotically larger f (n) = n lg n > (asymptotically larger) But not Polynomially larger The ratio is asymptotically less than for any positive constant k (polynomially smaller) Recurrence falls into gap between cases 2 and 3.

6. The proof of master theorem 27 Case 1 : dominated by the costs in the leaves. we have for some constant,then so,,which implies that..

6. The proof of master theorem 28 Case 1 : dominated by the costs in the leaves. Constant value

6. The proof of master theorem 29 Case 2 : distributed across the levels of the tree.

6. The proof of master theorem 30 Case 3 : dominated by the cost of the root. We assume that af (n/b) cf (n) for some constant and c < 1, all n b, ( Iterating j times )

Thank you Q & A 31