Updates HW#1 has been delayed until next MONDAY. There were two errors in the assignment. 2-1. Merge sort runs in Θ(n log n). Insertion sort runs in Θ(n2).

Slides:



Advertisements
Similar presentations
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 2 Prof. Erik Demaine.
Advertisements

Recurrences : 1 Chapter 3. Growth of function Chapter 4. Recurrences.
Introduction to Algorithms 6.046J
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
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.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
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.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 4. Recurrences - 1 Recurrences.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Analysis of Algorithms
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
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.
October 1, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Introduction to Algorithms Jiafen Liu Sept
Analysis of Algorithms
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
10/13/20151 CS 3343: Analysis of Algorithms Lecture 9: Review for midterm 1 Analysis of quick sort.
1 Computer Algorithms Lecture 7 Master Theorem Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
2IL50 Data Structures Fall 2015 Lecture 2: Analysis of Algorithms.
Project 2 due … Project 2 due … Project 2 Project 2.
CSC 413/513: Intro to Algorithms Merge Sort Solving Recurrences.
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
10/25/20151 CS 3343: Analysis of Algorithms Lecture 6&7: Master theorem and substitution method.
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.
Foundations II: Data Structures and Algorithms
Solving Recurrences with the Substitution Method.
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
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.
Spring 2015 Lecture 2: Analysis of Algorithms
1Computer Sciences. 2 GROWTH OF FUNCTIONS 3.2 STANDARD NOTATIONS AND COMMON FUNCTIONS.
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.
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.
2IL50 Data Structures Spring 2016 Lecture 2: Analysis of Algorithms.
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
Introduction to Algorithms: Recurrences
CS 3343: Analysis of Algorithms
Lecture 11. Master Theorem for analyzing Recursive relations
Divide-and-Conquer 6/30/2018 9:16 AM
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Introduction to Algorithms 6.046J
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Recursion-tree method
CS 3343: Analysis of Algorithms
Introduction to Algorithms
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
Algorithms and Data Structures Lecture III
Presentation transcript:

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). Consider a modification to Merge sort where n/k sublists of length k are sorted using Insertion sort and then merged by Merge sort.

Updates A) Show each n/k sublist can be sorted by Insertion Sort in Θ(n/k) worst case time. B) Show that the sublists can be merged in Θ(n lg(n/k)) worst case time. C) Skip. D) How should k be chosen in practice? (hint: philosophical)

Lecture 3: Solving Recurrences

Recurrences Recurrence: An equation that describes a function in terms of its value on smaller inputs. Example (MergeSort): T(n) =Θ(n) if n = 1, 2T(n/2) + Θ(n) if n>1

Recurrences We will study three techniques: 1.The substitution method 2.The recursion-tree method 3.The master method Sometimes more than one works well, sometimes none work well.

The Substitution Method The most general method: 1.Guess the form of the solution. 2.Verify using induction. 3.Solve for the constants.

Substitution Method: Example 1 Example: T(n) = 4T(n/2) + 100n Guess: T(n) = O(n 3 )

Substitution Method: Example 1 Example: T(n) = 4T(n/2) + 100n Proof: 1.Assume that T(1) = Θ(1). 2.Guess T(n) = O(n 3 ). We want to prove T(n) 0. 3.Verify by substituting into the recurrence. We assume this holds for T(n/2) 0, that is solving for constants, when c > 200 and n > 1. Always verify the base case(s) as well. Here Θ(1) < cn 3 for sufficiently large c.

A Tighter Bound? Example: T(n) = 4T(n/2) + 100n Guess: T(n) = O(n 2 )

A Tighter Bound? Example: T(n) = 4T(n/2) + 100n Proof: 1.Assume that T(1) = Θ(1). 2.Guess T(n) = O(n 2 ). We want to prove T(n) 0. 3.Verify by substituting into the recurrence. We assume this holds for T(n/2) 0. No valid assignment of c and n > 0 can be made! We have made a bad guess. We MUST prove the EXACT form of the inductive hypothesis (our guess).

Subtleties.. Example: T(n) = 4T(n/2) + 100n Guess T(n) = O(n 2 -n).

Subtleties.. Example: T(n) = 4T(n/2) + 100n Proof: 1.Assume that T(1) = Θ(1). 2.Guess T(n) = O(n 2 -n). We want to prove T(n) 0 and c 2 >0. 3.Verify by substituting into the recurrence. We assume this holds for T(n/2) 0, that is, c 2 >100.

Recursion Tree Method The Recursion Tree Method doesn’t necc. build a proof, but a good guess. You might use this method with the substitution method. The idea is to draw the tree and do the “accounting” the way we did with MergeSort last time. This can be unreliable, but it provides good intuition.

Example of recursion tree Solve T(n) = T(n/4) + T(n/2) + n 2 :

Example of recursion tree T(n)T(n) Solve T(n) = T(n/4) + T(n/2) + n 2 :

Example of recursion tree T(n/4) T(n/2) n2n2 Solve T(n) = T(n/4) + T(n/2) + n 2 :

Example of recursion tree Solve T(n) = T(n/4) + T(n/2) + n 2 : n2n2 (n/4) 2 (n/2) 2 T(n/16)T(n/8) T(n/4)

Example of recursion tree (n/16) 2 (n/8) 2 (n/4) 2 (n/2) 2  (1) … Solve T(n) = T(n/4) + T(n/2) + n 2 : n2n2

Example of recursion tree Solve T(n) = T(n/4) + T(n/2) + n 2 : (n/16) 2 (n/8) 2 (n/4) 2 (n/2) 2  (1) … n2n2

Example of recursion tree Solve T(n) = T(n/4) + T(n/2) + n 2 : (n/16) 2 (n/8) 2 (n/4) 2 (n/2) 2  (1) … n2n2

Example of recursion tree Solve T(n) = T(n/4) + T(n/2) + n 2 : (n/16) 2 (n/8) 2 (n/4) 2  (1) … n2n2 (n/2) 2 …

Example of recursion tree Solve T(n) = T(n/4) + T(n/2) + n 2 : (n/16) 2 (n/8) 2 (n/4) 2  (1) … … Total = =  (n 2 ) n2n2 (n/2) 2 geometric series

The Master Method The Master Theorem: Let a > 1 and b > 1 be constants. Let f(n) be a function and T(n) be defined on the non-negative integers as, T(n) = a T(n/b) + f(n). T(n) can be asymptotically bounded as follows: 1.If f(n) = O(n logba-ε ), then T(n) = Θ(n logba ) 2.If f(n) = Θ(n logba ), then T(n) = Θ(n logba lg n) 3.If f(n) = Ω(n logba+ ε ) and if af(n/b)<cf(n) for c < 1 and all sufficiently large n, then T(n) = Θ(f(n)).