Attribution Non-Commercial (BY-NC)

11 views

Attribution Non-Commercial (BY-NC)

- Introduction to the Theory of Computation
- DSA Written Assignment
- Data Structures a Algorithms Multiple Choset 3
- Data Structure
- Discrete Mathematics ebook.pdf
- pcm
- ps6
- NP Section
- Master.pdf
- Algorithm
- 10.1.1.162.1209[1]
- Solution of Second Order Nonlinear Singular Value Problems
- ada_viva
- The World in a Box
- next.docx
- Theory 12
- Simply Scheme
- CSE 101 Algorithm Lecture Notes 2
- Clojure High Performance Programming - Second Edition - Sample Chapter
- Nicolau Santos

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

- Introduction to the Theory of ComputationUploaded byskimdad
- DSA Written AssignmentUploaded bySayak Mitra
- Data Structures a Algorithms Multiple Choset 3Uploaded bysyrissco123
- Data StructureUploaded byJitender Kumar
- Discrete Mathematics ebook.pdfUploaded byrrs_1988
- pcmUploaded byMuhammad Usama
- ps6Uploaded bySiva Pulla
- NP SectionUploaded byspy_crash
- Master.pdfUploaded byNishu Rave
- AlgorithmUploaded byTanvi Gupta
- 10.1.1.162.1209[1]Uploaded byHasan özkul
- Solution of Second Order Nonlinear Singular Value ProblemsUploaded byAlexander Decker
- ada_vivaUploaded bykartik
- The World in a BoxUploaded bystefi idlab
- next.docxUploaded bybhatiaharryjassi
- Theory 12Uploaded bybhatiaharryjassi
- Simply SchemeUploaded byDiwakar
- CSE 101 Algorithm Lecture Notes 2Uploaded byphulam146
- Clojure High Performance Programming - Second Edition - Sample ChapterUploaded byPackt Publishing
- Nicolau SantosUploaded byjsofv5533
- ited.5.2.25.pdfUploaded byLê Thị Phương Viên
- 09-05Uploaded byHassan Ali
- lab#9Uploaded byanbreen
- Smax-triangle in a Convex Polygon, RevisitedUploaded byNguyen Huy Anh
- Complexity NpcUploaded byምንሼ ነው ዘመኑ
- Turing Machines - Iordache Eugen.pdfUploaded byEugen Iordache
- CS.7.PerformanceUploaded byAntonio
- Recursive SquaringUploaded byQuasar Chunawalla
- A Fast Compressive Bilateral FilterUploaded byAnonymous IbaxebQg0P
- log_linearization_sp12.pdfUploaded byDynamix Solver

- B47-1_Edtn_2007Uploaded byArun Cherian
- Hard Disk and Hard Drive Physical ComponentsUploaded byKumar Reddy
- Design and Construction of a Stabilized Variable Power SupplyUploaded byad_costin1522
- CHE555 Assignment 2Uploaded byEiman Uzmi
- Lab Write UpUploaded byRicky Aguilera
- Diego Farren - Thesis ShortUploaded byDiego Riedemann
- Mindanao 2020: Peace and Development Framework Plan 2011-2030 (Executive Summary)Uploaded byArangkada Philippines
- LanguageUploaded byMohd Hafiz
- study of gas and study guideUploaded byMarc Odermatt
- arttUploaded byArt Torrechante-Tiachon Marcelino
- chess lessonUploaded byapi-259470709
- Vx Works Rtos FinalUploaded byappiammu
- Census and SamplingUploaded byNorhayati_Y
- AUTOMIZATION OF KNITTING MACHINE IN TEXTILE INDUSTRY BASED ON ADVANCED MICROCONTROLLERUploaded byIJIERT-International Journal of Innovations in Engineering Research and Technology
- tqm pptUploaded byReema Dawra
- models of teaching portfolioUploaded byapi-310440861
- 1 2013.12 Update Training Overview v0.5.NotesUploaded bymanojkumar
- imb social studies lesson planUploaded byapi-297204430
- LESSON PLAN of CongruenceUploaded byFatikha Akfini Ananta Putri
- Ekonomi Bisnis Dan ManajerialUploaded byMaryam Burhanuddin
- Anhauser, Meet the NeanderthalsUploaded byLea Vukusic
- Who Was Luca PacioliUploaded byBisma Ramadhan
- Wiimote PhysicsUploaded byAnonymous hYHGFMBJm
- bcrUploaded byMarvin Marquez
- Samsung ATIV S GT-I8750Uploaded byAntónio Grade
- Pascal's Triangle The Royal Society Western History the Nobel Foundation the Fields Institute A New YearUploaded byMark Richard Hilbert(Mark Richard Rossetti)
- Multiple_Choice_Practice_for_PHYS11184.pdfUploaded byJosef Lyle H. Solis
- Darwall - Two Kinds of RespectUploaded byJulian Jonker
- International -World Class- Certificatlon for Hazardous Area Electrlcal EquipmentUploaded bygirish19
- SUIT Protocol Description v8.0.pdfUploaded byEzzudien Khames Hamed