Lecture 5

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Design and

Analysis of
Algorithm
Lecture 5: Recursion

Dr. Tauheed
Contents

Complexity of
recurrence
relation

2
Complexity of recurrence relation
• Iteration Method
• Recursion tree method
• Master Method
The recursion-tree
In a recursion tree, each node represents the cost of a single sub problem somewhere
in the set of recursive function invocations.

𝑇 ( 𝑛 )=3 . 𝑇 ( )
𝑛
4
+𝑐 𝑛
2
Example: Recursion Tree
𝑇 ( 𝑛 )=3 . 𝑇 ( )
𝑛
4
+𝑐 𝑛2
Master Theorem
The master method provides a “cookbook” method for solving recurrences of the form

, where, 1 and

1. if where
then
2. if
then
3. if
if for some c<1
then
Example: Master Theorem
Step 1:
Step 1:
Step 2: compute
Step 2: compute
Step 3: compute
Step 3: compute
Step 4: compare with
Step 4: compare with
Step 5: Choose the case: Case 1
Step 5: Choose the case: Case 2
Step 6:
Step 6:

Step 1:
Step 2: compute
𝑇 ( 𝑛 )= 𝜃 (𝑛𝑙𝑜𝑔 (𝑛))
Step 3: compute
Step 4: compare with
Step 5: Choose the case: Case 3
Step 6:
Example: Master Theorem
(a)

Answer: T(n) =
(b) Answer: T(n) =

Answer: T(n) = (f)


(c)

Answer: T(n) = Answer: T(n)= )


(d) (g)

Answer: T(n)= Answer: T(n)=

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy