Recurrences It continues… Jeff Chastine. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. A recurrence.

Slides:



Advertisements
Similar presentations
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
5/5/20151 Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
1 Issues with Matrix and Vector Issues with Matrix and Vector Quicksort Quicksort Determining Algorithm Efficiency Determining Algorithm Efficiency Substitution.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
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.
CS 253: Algorithms Chapter 4 Divide-and-Conquer Recurrences Master Theorem Credit: Dr. George Bebis.
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).
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Recurrence Examples.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
Chapter 4: Solution of recurrence relationships
Analysis of Algorithms CS 477/677 Recurrences Instructor: George Bebis (Appendix A, Chapter 4)
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions BIL741: Advanced.
Analysis of Algorithms
Analysis of Algorithms CS 477/677
Analyzing Recursive Algorithms A recursive algorithm can often be described by a recurrence equation that describes the overall runtime on a problem of.
MCA 202: Discrete Mathematics Instructor Neelima Gupta
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
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.
Getting Started Introduction to Algorithms Jeff Chastine.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 3.
Introduction to Algorithms Chapter 4: Recurrences.
Chapter 4. Recurrences. Outline Offers three methods for solving recurrences, that is for obtaining asymptotic bounds on the solution In the substitution.
Recurrences David Kauchak cs161 Summer Administrative Algorithms graded on efficiency! Be specific about the run times (e.g. log bases) Reminder:
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.
1 Algorithms CSCI 235, Fall 2015 Lecture 6 Recurrences.
Foundations II: Data Structures and Algorithms
Solving Recurrences with the Substitution Method.
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.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences.
Recurrences (in color) It continues…. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. When an algorithm.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
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.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 4.
Mathematical Foundations (Solving Recurrence)
Design and Analysis of Algorithms
Analysis of Algorithms CS 477/677
Lecture 11. Master Theorem for analyzing Recursive relations
Divide-and-Conquer 6/30/2018 9:16 AM
Unit 1. Sorting and Divide and Conquer
CS 3343: Analysis of Algorithms
Chapter 4: Divide and Conquer
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Ch 4: Recurrences Ming-Te Chi
Divide and Conquer (Merge Sort)
Merge Sort Solving Recurrences The Master Theorem
Divide-and-Conquer 7 2  9 4   2   4   7
Trevor Brown CS 341: Algorithms Trevor Brown
Ack: Several slides from Prof. Jim Anderson’s COMP 202 notes.
Analysis of Algorithms
Algorithms Recurrences.
Algorithms CSCI 235, Spring 2019 Lecture 6 Recurrences
Divide-and-Conquer 7 2  9 4   2   4   7
Quicksort Quick sort Correctness of partition - loop invariant
Algorithms and Data Structures Lecture III
Presentation transcript:

Recurrences It continues… Jeff Chastine

Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. A recurrence describes itself in terms of its value on smaller inputs There are four methods of solving these: substitution, iteration, recursion tree, or master method Jeff Chastine

What it looks like This is the recurrence of M ERGE -S ORT What this says is that the time involved is 1 if n = 1, Else, the time involved is 2 times calling on half the size of the array, plus n time to merge sorted sub-arrays T(n) = { Θ (1) 2T(n/2) + Θ (n) if n = 1 if n > 1 Jeff Chastine

Substitution Similar to induction Guess solution, and prove it holds true for next call Powerful method, but can sometimes be difficult to guess the solution! Jeff Chastine

Substitution Example: – T (n) = 2T (n/2) + n – Guess that T (n) = O(n lg n) We must prove that T (n)  cn lg n | c > 0 Assume it holds for n/2 as well T (n/2) = c(n/2) lg (n/2) + n// Rewrite using n/2 T (n)  2 (c(n/2) lg (n/2)) + n// Substitution = cn lg (n/2)) + n// Math stuff = cn (lg n – lg 2) + n = cn lg n – cn + n  cn lg n  c  1 Note:  means ‘for all’ Jeff Chastine

Subtleties Let T (n) = T (n/2) + T(n/2) + 1 Assume that T (n) = O(n) Then T (n/2) = c(n/2) T (n)  c(n/2) + c(n/2) + 1 = cn + 1 Which does not imply T (n)  cn Here, we’re correct, but off by a constant! Jeff Chastine

Subtleties We strengthen our guess: T (n)  cn – b T (n)  (c(n/2) – b) + (c(n/2) – b) + 1 = cn – 2b + 1  cn – b  b > 1 Jeff Chastine

One Last Example Jeff Chastine

Iteration Method Expand out the recurrence T(n) = 3T(n/4) + n T(n) = 3(3T(n/16) + (n/4)) + n T(n) = 3((3T(n/64) + 3(n/16))+ (n/4))) + n T(n) < n + 3n/4 + 9n/ n/64 + … n Σ i=0 ∞ ( ) 3 4 i = 4n = n /4 = n Jeff Chastine

Recursion Tree Method A recursion tree is built We sum up each level, Total cost = number of levels * cost at each level Usually used to generate a good guess for the substitution method Could still be used as direct proof Example: T (n) = 3T (n/4) +  (n 2 ) Jeff Chastine

T(n)T(n)

cn 2 T(n/4) Jeff Chastine

cn 2 c(n/4) 2 T(n/16) Jeff Chastine

cn 2 c(n/4) 2 c(n/16) 2 T(1) Jeff Chastine

cn 2 c(n/4) 2 c(n/16) 2 T(1) cn 2 3/16 cn 2 (3/16) 2 cn 2  (n log 4 3 ) Jeff Chastine

Questions How many levels does this tree have? The subproblem at depth i is n/4 i When does the subproblem hit size 1? – n/4 i = 1 – n = 4 i – lg 4 n = i Therefore, the tree has lg 4 n levels The cost at each level is 3 i c(n/4 i ) 2 The last level has 3 log 4 n nodes = n log 4 3 Jeff Chastine

The Master's Method When it has this form: T(n) = aT(n/b) + f(n) If f (n) = Ο(n log b a-ε ) for some constant ε>0, then T (n) = Θ (n log b a ) If f (n) = Θ(n log b a ), then T (n) = Θ (n log b a lgn) If f (n) = Ω (n log b a+ε ) for some constant ε>0, then T (n) = Θ (f (n)) Jeff Chastine

T(n) = 9T(n/3) + n – a = 9, b = 3 thus n log b a = n log 3 9 = n 2 T(n) = T(2n/3) + 1 – a = 1, b = 3/2 thus n log b a = n log 3/2 1 = n 0 = 1 Problem: – T(n) = 2T(n/2) + nlgn Jeff Chastine