11 views

Uploaded by Jagrut Kosti

- 05 Simple Recursion
- MIT18_310F13_Ch7
- 6201 Scheduling 2
- Summer.2012.e8 Solutions
- 199 Paper
- Re Curses
- Further Problems - Series Solution
- DSPQNAUNITI
- geb_v3_2
- Generating Functions
- final-l15
- What is a Function
- Algorithm Analysis Complexity
- IIyr_EI
- Relationship Sexual (Vers9)
- hw_08_sol
- c Programs
- Inverse dynamic problem in robots using Gibbs-Appell equations
- Data Structures
- Introduction to Programming Using Fortran 95-2003-2008

You are on page 1of 18

CS 3110

Textbook readings:

Chapter 4

1/12

Overview

What are recurrence relations? What is their relationship to algorithm design? Methods to solve them: Substitution (induction in disguise) Recursion trees Master Theorem

2/12

A recurrence relation expresses the value of a function f for an argument n in terms of the values of f for arguments less than n. Examples:

f (n) =

1 if n 1 2f (n/2) + n if n > 1

f (n) =

3/12

The running time of a recursive algorithm is easily expressed using a recurrence relation. Example: (Merge-Sort) Merge-Sort(A, p, r) 1 if r > p 2 then q p+r 2 3 Merge-Sort(A, p, q) 4 Merge-Sort(A, q + 1, r) 5 Merge(A, p, q, r)

4/12

The running time of a recursive algorithm is easily expressed using a recurrence relation. Example: (Merge-Sort) Merge-Sort(A, p, r) 1 if r > p 2 then q p+r 2 3 Merge-Sort(A, p, q) 4 Merge-Sort(A, q + 1, r) 5 Merge(A, p, q, r) Running time: T (n) = O(1) if n 1 2T (n/2) + O(n) if n > 1

4/12

Given: Set T of n tasks t1 , t2 , . . . , tn Set K of n contractors k1 , k2 , . . . , kn Contractor ki charges cij dollars for performing task tj Assign one task to every contractor Goal: Minimize the total cost C. A recurrence relation: C = c(T, K) c(T, K) = the minimal cost of assigning the tasks in T to the contractors in K. c(T, K) = 0 if T = min1in (ci1 + c(T \ {t1 }, K \ {ki })) if T =

5/12

Given two algorithms for the same problem. Running times: Algorithm 1: T1 (n) = 2T1 (n/2) + O(n lg n) Algorithm 2: T2 (n) = 3T2 (n/2) + O(n) Which one is faster?

6/12

Given two algorithms for the same problem. Running times: Algorithm 1: T1 (n) = 2T1 (n/2) + O(n lg n) Algorithm 2: T2 (n) = 3T2 (n/2) + O(n) Which one is faster? We need closed forms of T1 (n) and T2 (n). (Expressions for T1 (n) and T2 (n) that are not recurrence relations.)

6/12

Given two algorithms for the same problem. Running times: Algorithm 1: T1 (n) = 2T1 (n/2) + O(n lg n) Algorithm 2: T2 (n) = 3T2 (n/2) + O(n) Which one is faster? We need closed forms of T1 (n) and T2 (n). (Expressions for T1 (n) and T2 (n) that are not recurrence relations.) To solve a recurrence relation means to derive such a closed form from the recurrence relation.

6/12

Substitution method: Make a guess Verify the guess using induction Recursion trees: Visualize how the recurrence unfolds May lead to a guess to be veried using substitution If done carefully, may lead to an exact solution Master theorem: Cook-book solution to a common class of recurrence relations

7/12

Substitution Method

Three steps: 1. Make a guess 2. Prove that the guess is correct assuming that it can be veried for all n less than some n0 . (inductive step) 3. Verify the guess for all n n0 . (base case)

8/12

Substitution Method

Three steps: 1. Make a guess 2. Prove that the guess is correct assuming that it can be veried for all n less than some n0 . (inductive step) 3. Verify the guess for all n n0 . (base case) Why do we switch the two parts of the inductive proof?

8/12

Substitution Method

Three steps: 1. Make a guess 2. Prove that the guess is correct assuming that it can be veried for all n less than some n0 . (inductive step) 3. Verify the guess for all n n0 . (base case) Why do we switch the two parts of the inductive proof? Our guess is vague.

8/12

Substitution Method

Three steps: 1. Make a guess 2. Prove that the guess is correct assuming that it can be veried for all n less than some n0 . (inductive step) 3. Verify the guess for all n n0 . (base case) Why do we switch the two parts of the inductive proof? Our guess is vague. Example: T (n) cn lg n (that is, T (n) = O(n lg n))

We do not know c, and we do not want to know; we do not care. The inductive step may work only for certain values of c. The base case usually works for any value of c.

CS 3110 Recurrence Relations 8/12

Experience, inspiration, black magic, . . . Recursion trees help us to visualize how the recurrence unfolds. If everything fails, prove loose upper and lower bounds and tighten them.

9/12

Recursion Trees

T (n) = 3T (n/4) + n2 n2

Cost n2

n 2 4

n 2 4

n 2 4

3 16

n2

n 2 16

n 2 16

n 2 16

n 2 16

n 2 16

n 2 16

n 2 16

n 2 16

n 2 16

3 2 16

n2

T (1) T (1)

T (1)

O(nlog4 3 )

Cost of the tree = sum of the costs of the levels T (n) = (n2 )

CS 3110 Recurrence Relations 10/12

Master Theorem

Theorem: (Master Theorem) Let a 1 and b > 1, let f (n) be a function over the positive integers, and let T (n) be given by the following recurrence: T (n) = aT (n/b) + f (n) (i) If f (n) = O(nlogb a ), for some > 0, then T (n) = (nlogb a ). (ii) If f (n) = (nlogb a ), then T (n) = (nlogb a lg n). (iii) If f (n) = (nlogb a+ ), for some > 0, and af (n/b) cf (n), for some c < 1 and all n n0 , then T (n) = (f (n)).

11/12

Summary

A recurrence relation expresses the value of a function f for an argument n in terms of the values of f for arguments less than n. Recurrence relations are useful for expressing the running times of recursive algorithms and the costs of optimal solutions to optimization problems. There are three methods to solve recurrence relations: Substitution method Recursion trees Master theorem

12/12

- 05 Simple RecursionUploaded bySudarshan Muralidhar
- MIT18_310F13_Ch7Uploaded bybhar
- 6201 Scheduling 2Uploaded bystocktrial1
- Summer.2012.e8 SolutionsUploaded byRaj Shetty
- 199 PaperUploaded byacouillault
- Re CursesUploaded byP6E7P7
- Further Problems - Series SolutionUploaded byBayeeshmaal Arawani Ramsundar
- DSPQNAUNITIUploaded bysurendrarakshit
- geb_v3_2Uploaded byitalianmonkey14
- Generating FunctionsUploaded byAditya Ravichandran
- final-l15Uploaded bysenthil.r
- What is a FunctionUploaded bylouie_arnaiz
- Algorithm Analysis ComplexityUploaded byamandeep651
- IIyr_EIUploaded byRahul Sakarey
- Relationship Sexual (Vers9)Uploaded byKen Dawber
- hw_08_solUploaded bypoloram
- c ProgramsUploaded byRaju Puppala
- Inverse dynamic problem in robots using Gibbs-Appell equationsUploaded byali
- Data StructuresUploaded bysureshrockz
- Introduction to Programming Using Fortran 95-2003-2008Uploaded byPedro Aires
- variableKDtree_kubica_vtreesUploaded byFred Doan
- 3 Encryption Error CheckingUploaded byAnubha Yadav
- sortOpenMPUploaded bySilvio Berluschi
- Data Structure and AlgorithmsUploaded byየዓለምዘውድ መኮንን
- Solving Every Sudoku PuzzleUploaded bysrivatsa
- Web Ninin SlidesUploaded byszordin
- C Ques University Short Listed1Uploaded byJanaki Mahadevan
- fptschool-book.pdfUploaded bysumi_11
- Hardware Descriptive Languages 2Uploaded byPuspala Manojkumar
- Transportation Problems1Uploaded byJaphet Repolledo

- New EC3001 MathsUploaded byaidanwimpress
- dmchap10Uploaded byMrJoshuaUSA
- Week3.2Uploaded byhfzmusama
- 2. B.E. Auto syllabusUploaded byJagadesh Abbu
- 1. Questions & Answers on Discrete Time Signals and SystemsUploaded bykibrom atsbha
- Numerical Analysis And Differential Equations -Part b.pdfUploaded bySanjeev Shukla
- MECE 211 Text BookUploaded bymutlu_bağdaş
- Calculus of Finite DifferencesUploaded byChristiano Santos
- 06_02_45_52.pdfUploaded byBhily Quipo
- Smith Wessel 1990 Gridding With Continuous Curvature Splines in TensionUploaded bycrescentesoto
- Graph Theory Session 34Uploaded byJon Jijong
- Recurrence AlgoUploaded byRituparna Majumdar
- Lecture 02Uploaded bymanikandarajan_gr
- Uhlig, H. a Toolkit for Analyzing Nonlinear Dynamic Stochastic Models EasilyUploaded byJuliana Tessari
- Simnon - Tutoria.pdfUploaded byCláudia Miranda
- MathsUploaded bybrajeshbj
- recurrence relationsUploaded byapi-298592212
- (ebook-pdf) - Mathematics - Advanced determinant calculusUploaded bymjk
- 2005 Stability of methods for advanced differential equations with piecewise continuous argumentsUploaded byMailing Báez
- Recurrence_1Uploaded bysamgalforyou
- RECURRENCIASUploaded byTaipe Lopez Andy
- 201499031 J C Burkill Theory of Ordinary Differential EquationsUploaded byPawan Mishra
- 6 - 4 - Lecture 47 Discrete CalculusUploaded byRahulsinghoooo
- Schemes for Partial Differential EquationsUploaded bygabo2008
- CS301 Engineering Mathematics IIIUploaded byashwath k a
- MAT 105 SyllabusUploaded byAnkit Singh
- Mathematical Modelling Notes (Murdoch University)Uploaded byDhruvishaGosai
- MCA R16 21082016Uploaded byBalakrishna Pulaparthi
- 20161122131116chapter 8 - Advanced Counting TechniquesUploaded byIrfan Fazail
- Lecture#18(1)Uploaded byNew1122