Data Structure and Algorithms
Solving recurrences
meghav@kannuruniv.ac.in
Presented by
Megha V
Research scholar
Dept. of IT
Kannur University
Algorithm
Algorithms are of two types:
1. Recursive
2. Non recursive
meghav@kannuruniv.ac.in
Solving Recurrences
Iteration method
Substitution method
Recursion Tree method
Master’s Theorem
meghav@kannuruniv.ac.in
Recurrences and Running Time
• Recursive equation is an equation that defines a
sequence recursively. It is normally in the form:
T(n) = T(n-1) + n for all n≥0
T(0) = 0 initial condition
Recurrences arise when an algorithm contains recursive
calls to itself
•
•
•
What is the actual running time of the algorithm?
Need to solve the recurrence
– Find an explicit formula of the expression
– Bound the recurrence by an expression that involves n
meghav@kannuruniv.ac.in
Example Recurrences
• T(n) = T(n-1) + n Θ(n2)
– Recursive algorithm that loops through the input to
eliminate one item
• T(n) = T(n/2) + c Θ(lgn)
– Recursive algorithm that halves the input in one step
• T(n) = T(n/2) + n Θ(n)
– Recursive algorithm that halves the input but must
examine every item in the input
• T(n) = 2T(n/2) + 1 Θ(n)
– Recursive algorithm that splits the input into 2 halves
and does a constant amount of other work
meghav@kannuruniv.ac.in
Methods for Solving Recurrences
• Iteration method
• Substitution method
• Recursion tree method
• Master method
meghav@kannuruniv.ac.in
The Iteration Method
• Convert the recurrence into a summation and try
to bound it using known series
– Iterate the recurrence until the initial condition is
reached.
– Use back-substitution to express the recurrence in
terms of n and the initial (boundary) condition.
meghav@kannuruniv.ac.in
The Iteration Method
T(n) = c + T(n/2)
T(n) = c + T(n/2)
= c + c + T(n/4)
= c + c + c + T(n/8)
Assume n = 2k
T(n) = c + c + … + c + T(1)
k times
= clgn + T(1)
= Θ(lgn)
T(n/2) = c + T(n/4)
T(n/4) = c + T(n/8)
meghav@kannuruniv.ac.in
Iteration Method – Example
T(n) = n + 2T(n/2)
T(n) = n + 2T(n/2)
= n + 2(n/2 + 2T(n/4))
= n + n + 4T(n/4)
= n + n + 4(n/4 + 2T(n/8))
= n + n + n + 8T(n/8)
… = in + 2iT(n/2i)
= kn + 2kT(1)
= nlgn + nT(1) = Θ(nlgn)
Assume: n = 2k
T(n/2) = n/2 + 2T(n/4)
meghav@kannuruniv.ac.in
The substitution method
1. Guess a solution
2. Use induction to prove that the
solution works
meghav@kannuruniv.ac.in
Substitution method
• Guess a solution
–
–
T(n) = O(g(n))
Induction goal: apply the definition of the asymptotic notation
• T(n) ≤ d g(n), for some d > 0 and n ≥ n0
– Induction hypothesis: T(k) ≤ d g(k) for all k < n
• Prove the induction goal
– Use the induction hypothesis to find some values of the
constants d and n0 for which the induction goal holds
(strong induction)
meghav@kannuruniv.ac.in
Example: Binary Search
T(n) = c + T(n/2)
Guess: T(n) = O(lgn)
•
–
–
Induction goal: T(n) ≤ d lgn, for some d and n ≥ n0
Induction hypothesis: T(n/2) ≤ d lg(n/2)
• Proof of induction goal:
T(n) = T(n/2) + c ≤ d lg(n/2) + c
= d lgn – d + c ≤ d lgn
if: – d + c ≤ 0, d ≥ c
• Base case? meghav@kannuruniv.ac.in
Example 2
T(n) = T(n-1) + n
Guess: T(n) = O(n2)
– Induction goal: T(n) ≤ c n2, for some c and n ≥ n0
•
– Induction hypothesis: T(n-1) ≤ c(n-1)2 for all k < n
• Proof of induction goal:
T(n) = T(n-1) + n ≤ c (n-1)2 + n
= cn2 – (2cn – c - n) ≤ cn2
if: 2cn – c – n ≥ 0  c ≥ n/(2n-1)  c ≥ 1/(2 – 1/n)
– For n ≥ 1  2 – 1/n ≥ 1  any c ≥ 1 will work
meghav@kannuruniv.ac.in
Example 3
T(n) = 2T(n/2) + n
Guess: T(n) = O(nlgn)
•
– Induction goal: T(n) ≤ cn lgn, for some c and n ≥ n0
– Induction hypothesis: T(n/2) ≤ cn/2 lg(n/2)
• Proof of induction goal:
T(n) = 2T(n/2) + n ≤ 2c (n/2)lg(n/2) + n
= cn lgn – cn + n ≤ cn lgn
if: - cn + n ≤ 0  c ≥ 1
meghav@kannuruniv.ac.in
Example 4 - Substitution
T(n) = 3T(n/4) + cn2
• Guess: T(n) = O(n2)
– Induction goal: T(n) ≤ dn2, for some d and n ≥ n0
– Induction hypothesis: T(n/4) ≤ d (n/4)2
• Proof of induction goal:
T(n) = 3T(n/4) + cn2
≤ 3d (n/4)2 + cn2
= (3/16) d n2+ cn2
≤ d n2 if: d ≥ (16/13)c
• Therefore: T(n) = O(n2)
meghav@kannuruniv.ac.in
The recursion-tree method
Convert the recurrence into a tree:
– Each node represents the cost incurred at various
levels of recursion
– Sum up the costs of all levels
Used to “guess” a solution for the recurrence
meghav@kannuruniv.ac.in
Example 1
W(n) = 2W(n/2) + n2
•
•
•
•
Subproblem size at level i is: n/2i
Subproblem size hits 1 when 1 = n/2i i = lgn
Cost of the problem at level i = (n/2i)2 No. of nodes at level i = 2i
Total cost:
2
1
1 1
 1 
i
W (n)    2lgn
W(1)  n2
   n  n2
   O(n) n2
 O(n)  2n2

i0  2 
i0  2 
lgn1
n2 lgn1
 1 
i
i0 2i
 W(n) = O(n2) meghav@kannuruniv.ac.in
Example 2
E.g.: T(n) = 3T(n/4) + cn2
• Subproblem size at level i is: n/4i
• Subproblem size hits 1 when 1 = n/4i  i = log4n
• Cost of a node at level i = c(n/4i)2
• Number of nodes at level i = 3i  last level has 3log
4
n = nlog
4
3 nodes
• Total cost:
 T(n) = O(n2) 16
1
16
16
2
 O(n )
2
2
2 log4 3

log4 3
 log4 3

1
  cn  n
3
cn   n

 
 3 
i
cn  n 
 
 
T(n)  


i0 
log4 n1
 3 
i
i0
Master’s method
• solving recurrences of the form:
Idea: compare f(n) with 𝑛𝑙𝑜𝑔𝑏𝑎
• f(n) is asymptotically smaller or larger than 𝑛𝑙𝑜𝑔𝑏𝑎
by a polynomial factor n
• f(n) is asymptotically equal with 𝑛𝑙𝑜𝑔𝑏𝑎

b

 
where, a ≥ 1, b > 1, and f(n) > 0
T(n)  aT n   f (n)
meghav@kannuruniv.ac.in
Master’s method
Case 1: if f(n) = 𝑂(𝑛𝑙𝑜𝑔𝑏𝑎−)for some  > 0, then: T(n) = (𝑛𝑙𝑜𝑔𝑏𝑎 )
Case 2: if f(n) = (𝑛𝑙𝑜𝑔𝑏𝑎), then: T(n) = (𝑛𝑙𝑜𝑔𝑏𝑎 lgn)
Case 3: if f(n) = (𝑛𝑙𝑜𝑔𝑏𝑎+) for some  > 0, and if
af(n/b) ≤ cf(n) for some c < 1 and all sufficiently large n, then:
T(n) = (f(n))
meghav@kannuruniv.ac.in
Example 1
T(n) = 2T(n/2) + n
a = 2, b = 2, log22 = 1
Compare 𝑛𝑙𝑜𝑔22 with f(n) = n
 f(n) = (n)  Case 2
 T(n) = (nlgn)
meghav@kannuruniv.ac.in
Example 2
T(n) = 2T(n/2) + n2
a = 2, b = 2, log22 = 1
Compare n with f(n) = n2
 f(n) = (n1+) Case 3  verify regularity cond.
a f(n/b) ≤ c f(n)
 2 n2/4 ≤ c n2  c = ½ is a solution (c<1)
 T(n) = (n2)
meghav@kannuruniv.ac.in
Examples 3
T(n) = 2T(n/2) +
a = 2, b = 2, log22 = 1
Compare n with f(n) = n1/2
 f(n) = O(n1-) Case 1
 T(n) = (n)
n
meghav@kannuruniv.ac.in
Examples
T(n) = 3T(n/4) + nlgn
a = 3, b = 4, log43 = 0.793
Compare n0.793with f(n) = nlgn
f(n) = (nlog
4
3+ ) Case 3
Check regularity condition:
3(n/4)lg(n/4) ≤ (3/4)nlgn = c f(n), c=3/4
T(n) = (nlgn)
meghav@kannuruniv.ac.in
Assignment
Solve the following recurrence using Master’s method
1. T(n) = 9T(n/3)+n
2. T(n) = 16T(n/4)+n3
3. T(n) = 8T(n/2)+n2
4. T(n) = 2T(n/2)+n
meghav@kannuruniv.ac.in

More Related Content

PDF
Elements of visual perception
PDF
Introduction to Operating Systems
PPTX
Pumping lemma
PPTX
Problem solving in Artificial Intelligence.pptx
PPTX
Phases of Compiler
PPT
Recursion tree method
PPT
Unit 1 - Introduction to Software Engineering.ppt
PPTX
Urban rural presentation
Elements of visual perception
Introduction to Operating Systems
Pumping lemma
Problem solving in Artificial Intelligence.pptx
Phases of Compiler
Recursion tree method
Unit 1 - Introduction to Software Engineering.ppt
Urban rural presentation

What's hot (20)

PPTX
Asymptotic Notations
PPT
Recurrences
PPT
Amortized Analysis of Algorithms
PPTX
daa-unit-3-greedy method
PPT
SINGLE-SOURCE SHORTEST PATHS
PDF
Time and Space Complexity
PPT
1.1 binary tree
PDF
Optimal binary search tree
PPTX
Merge sort and quick sort
PDF
COMPILER DESIGN- Syntax Directed Translation
PPTX
heap Sort Algorithm
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PDF
PPTX
Graph coloring using backtracking
PPTX
Topological Sorting
PDF
Syntax directed translation
PPTX
Complexity analysis in Algorithms
PPT
Sum of subsets problem by backtracking 
DOC
Time and space complexity
PPT
Randomized algorithms ver 1.0
Asymptotic Notations
Recurrences
Amortized Analysis of Algorithms
daa-unit-3-greedy method
SINGLE-SOURCE SHORTEST PATHS
Time and Space Complexity
1.1 binary tree
Optimal binary search tree
Merge sort and quick sort
COMPILER DESIGN- Syntax Directed Translation
heap Sort Algorithm
Algorithms Lecture 2: Analysis of Algorithms I
Graph coloring using backtracking
Topological Sorting
Syntax directed translation
Complexity analysis in Algorithms
Sum of subsets problem by backtracking 
Time and space complexity
Randomized algorithms ver 1.0
Ad

Similar to Solving recurrences (20)

PPT
Recurrences-DATA ANALYSIS ALGORITHMS.ppt
PPTX
T2311 - Ch 4_Part1.pptx
PPT
recurrence relation is explained in this
PPTX
3. D&C and Recurrence Relation.ppYtxVVVV
PDF
Recurrence relation solutions
PPT
recurrence relations in analysis of algorithm
PDF
3.pdf
PPTX
Chapter 3 - Methods of Algorithm Analysis.pptx
PPTX
Divide and Conquer in DAA concept. For B Tech CSE
PDF
CS330-Lectures Statistics And Probability
PPTX
2.pptx
PDF
Recurrences
PPT
Time complexity
PPTX
recurrence relation on ca1 topic by makaut.pptx
PDF
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
PPT
3. Recursion and Recurrences.ppt detail about recursive learning
PPT
04_Recurrences_1.ppt
PPT
Divide and conquer
PPTX
Algorithm Design and Complexity - Course 3
PDF
Recurrence relation
Recurrences-DATA ANALYSIS ALGORITHMS.ppt
T2311 - Ch 4_Part1.pptx
recurrence relation is explained in this
3. D&C and Recurrence Relation.ppYtxVVVV
Recurrence relation solutions
recurrence relations in analysis of algorithm
3.pdf
Chapter 3 - Methods of Algorithm Analysis.pptx
Divide and Conquer in DAA concept. For B Tech CSE
CS330-Lectures Statistics And Probability
2.pptx
Recurrences
Time complexity
recurrence relation on ca1 topic by makaut.pptx
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
3. Recursion and Recurrences.ppt detail about recursive learning
04_Recurrences_1.ppt
Divide and conquer
Algorithm Design and Complexity - Course 3
Recurrence relation
Ad

More from Megha V (20)

PPTX
Soft Computing Techniques_Part 1.pptx
PPTX
JavaScript- Functions and arrays.pptx
PPTX
Introduction to JavaScript
PPTX
Python Exception Handling
PPTX
Python- Regular expression
PPTX
File handling in Python
PPTX
Python programming -Tuple and Set Data type
PPTX
Python programming –part 7
PPTX
Python programming Part -6
PPTX
Python programming: Anonymous functions, String operations
PPTX
Python programming- Part IV(Functions)
PPTX
Python programming –part 3
PPTX
Parts of python programming language
PPTX
Python programming
PPTX
Strassen's matrix multiplication
PPTX
Algorithm Analysis
PPTX
Algorithm analysis and design
PPTX
Genetic algorithm
PPTX
UGC NET Paper 1 ICT Memory and data
PPTX
Seminar presentation on OpenGL
Soft Computing Techniques_Part 1.pptx
JavaScript- Functions and arrays.pptx
Introduction to JavaScript
Python Exception Handling
Python- Regular expression
File handling in Python
Python programming -Tuple and Set Data type
Python programming –part 7
Python programming Part -6
Python programming: Anonymous functions, String operations
Python programming- Part IV(Functions)
Python programming –part 3
Parts of python programming language
Python programming
Strassen's matrix multiplication
Algorithm Analysis
Algorithm analysis and design
Genetic algorithm
UGC NET Paper 1 ICT Memory and data
Seminar presentation on OpenGL

Recently uploaded (20)

PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Website Design Services for Small Businesses.pdf
PPTX
most interesting chapter in the world ppt
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Microsoft Office 365 Crack Download Free
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PDF
E-Commerce Website Development Companyin india
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
Guide to Food Delivery App Development.pdf
Advanced SystemCare Ultimate Crack + Portable (2025)
Website Design Services for Small Businesses.pdf
most interesting chapter in the world ppt
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
CCleaner 6.39.11548 Crack 2025 License Key
Microsoft Office 365 Crack Download Free
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Full-Stack Developer Courses That Actually Land You Jobs
E-Commerce Website Development Companyin india
How to Use SharePoint as an ISO-Compliant Document Management System
Visual explanation of Dijkstra's Algorithm using Python
Wondershare Recoverit Full Crack New Version (Latest 2025)
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Autodesk AutoCAD Crack Free Download 2025
Salesforce Agentforce AI Implementation.pdf
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
CNN LeNet5 Architecture: Neural Networks
Guide to Food Delivery App Development.pdf

Solving recurrences

  • 1. Data Structure and Algorithms Solving recurrences meghav@kannuruniv.ac.in Presented by Megha V Research scholar Dept. of IT Kannur University
  • 2. Algorithm Algorithms are of two types: 1. Recursive 2. Non recursive meghav@kannuruniv.ac.in
  • 3. Solving Recurrences Iteration method Substitution method Recursion Tree method Master’s Theorem meghav@kannuruniv.ac.in
  • 4. Recurrences and Running Time • Recursive equation is an equation that defines a sequence recursively. It is normally in the form: T(n) = T(n-1) + n for all n≥0 T(0) = 0 initial condition Recurrences arise when an algorithm contains recursive calls to itself • • • What is the actual running time of the algorithm? Need to solve the recurrence – Find an explicit formula of the expression – Bound the recurrence by an expression that involves n meghav@kannuruniv.ac.in
  • 5. Example Recurrences • T(n) = T(n-1) + n Θ(n2) – Recursive algorithm that loops through the input to eliminate one item • T(n) = T(n/2) + c Θ(lgn) – Recursive algorithm that halves the input in one step • T(n) = T(n/2) + n Θ(n) – Recursive algorithm that halves the input but must examine every item in the input • T(n) = 2T(n/2) + 1 Θ(n) – Recursive algorithm that splits the input into 2 halves and does a constant amount of other work meghav@kannuruniv.ac.in
  • 6. Methods for Solving Recurrences • Iteration method • Substitution method • Recursion tree method • Master method meghav@kannuruniv.ac.in
  • 7. The Iteration Method • Convert the recurrence into a summation and try to bound it using known series – Iterate the recurrence until the initial condition is reached. – Use back-substitution to express the recurrence in terms of n and the initial (boundary) condition. meghav@kannuruniv.ac.in
  • 8. The Iteration Method T(n) = c + T(n/2) T(n) = c + T(n/2) = c + c + T(n/4) = c + c + c + T(n/8) Assume n = 2k T(n) = c + c + … + c + T(1) k times = clgn + T(1) = Θ(lgn) T(n/2) = c + T(n/4) T(n/4) = c + T(n/8) meghav@kannuruniv.ac.in
  • 9. Iteration Method – Example T(n) = n + 2T(n/2) T(n) = n + 2T(n/2) = n + 2(n/2 + 2T(n/4)) = n + n + 4T(n/4) = n + n + 4(n/4 + 2T(n/8)) = n + n + n + 8T(n/8) … = in + 2iT(n/2i) = kn + 2kT(1) = nlgn + nT(1) = Θ(nlgn) Assume: n = 2k T(n/2) = n/2 + 2T(n/4) meghav@kannuruniv.ac.in
  • 10. The substitution method 1. Guess a solution 2. Use induction to prove that the solution works meghav@kannuruniv.ac.in
  • 11. Substitution method • Guess a solution – – T(n) = O(g(n)) Induction goal: apply the definition of the asymptotic notation • T(n) ≤ d g(n), for some d > 0 and n ≥ n0 – Induction hypothesis: T(k) ≤ d g(k) for all k < n • Prove the induction goal – Use the induction hypothesis to find some values of the constants d and n0 for which the induction goal holds (strong induction) meghav@kannuruniv.ac.in
  • 12. Example: Binary Search T(n) = c + T(n/2) Guess: T(n) = O(lgn) • – – Induction goal: T(n) ≤ d lgn, for some d and n ≥ n0 Induction hypothesis: T(n/2) ≤ d lg(n/2) • Proof of induction goal: T(n) = T(n/2) + c ≤ d lg(n/2) + c = d lgn – d + c ≤ d lgn if: – d + c ≤ 0, d ≥ c • Base case? meghav@kannuruniv.ac.in
  • 13. Example 2 T(n) = T(n-1) + n Guess: T(n) = O(n2) – Induction goal: T(n) ≤ c n2, for some c and n ≥ n0 • – Induction hypothesis: T(n-1) ≤ c(n-1)2 for all k < n • Proof of induction goal: T(n) = T(n-1) + n ≤ c (n-1)2 + n = cn2 – (2cn – c - n) ≤ cn2 if: 2cn – c – n ≥ 0  c ≥ n/(2n-1)  c ≥ 1/(2 – 1/n) – For n ≥ 1  2 – 1/n ≥ 1  any c ≥ 1 will work meghav@kannuruniv.ac.in
  • 14. Example 3 T(n) = 2T(n/2) + n Guess: T(n) = O(nlgn) • – Induction goal: T(n) ≤ cn lgn, for some c and n ≥ n0 – Induction hypothesis: T(n/2) ≤ cn/2 lg(n/2) • Proof of induction goal: T(n) = 2T(n/2) + n ≤ 2c (n/2)lg(n/2) + n = cn lgn – cn + n ≤ cn lgn if: - cn + n ≤ 0  c ≥ 1 meghav@kannuruniv.ac.in
  • 15. Example 4 - Substitution T(n) = 3T(n/4) + cn2 • Guess: T(n) = O(n2) – Induction goal: T(n) ≤ dn2, for some d and n ≥ n0 – Induction hypothesis: T(n/4) ≤ d (n/4)2 • Proof of induction goal: T(n) = 3T(n/4) + cn2 ≤ 3d (n/4)2 + cn2 = (3/16) d n2+ cn2 ≤ d n2 if: d ≥ (16/13)c • Therefore: T(n) = O(n2) meghav@kannuruniv.ac.in
  • 16. The recursion-tree method Convert the recurrence into a tree: – Each node represents the cost incurred at various levels of recursion – Sum up the costs of all levels Used to “guess” a solution for the recurrence meghav@kannuruniv.ac.in
  • 17. Example 1 W(n) = 2W(n/2) + n2 • • • • Subproblem size at level i is: n/2i Subproblem size hits 1 when 1 = n/2i i = lgn Cost of the problem at level i = (n/2i)2 No. of nodes at level i = 2i Total cost: 2 1 1 1  1  i W (n)    2lgn W(1)  n2    n  n2    O(n) n2  O(n)  2n2  i0  2  i0  2  lgn1 n2 lgn1  1  i i0 2i  W(n) = O(n2) meghav@kannuruniv.ac.in
  • 18. Example 2 E.g.: T(n) = 3T(n/4) + cn2 • Subproblem size at level i is: n/4i • Subproblem size hits 1 when 1 = n/4i  i = log4n • Cost of a node at level i = c(n/4i)2 • Number of nodes at level i = 3i  last level has 3log 4 n = nlog 4 3 nodes • Total cost:  T(n) = O(n2) 16 1 16 16 2  O(n ) 2 2 2 log4 3  log4 3  log4 3  1   cn  n 3 cn   n     3  i cn  n      T(n)     i0  log4 n1  3  i i0
  • 19. Master’s method • solving recurrences of the form: Idea: compare f(n) with 𝑛𝑙𝑜𝑔𝑏𝑎 • f(n) is asymptotically smaller or larger than 𝑛𝑙𝑜𝑔𝑏𝑎 by a polynomial factor n • f(n) is asymptotically equal with 𝑛𝑙𝑜𝑔𝑏𝑎  b    where, a ≥ 1, b > 1, and f(n) > 0 T(n)  aT n   f (n) meghav@kannuruniv.ac.in
  • 20. Master’s method Case 1: if f(n) = 𝑂(𝑛𝑙𝑜𝑔𝑏𝑎−)for some  > 0, then: T(n) = (𝑛𝑙𝑜𝑔𝑏𝑎 ) Case 2: if f(n) = (𝑛𝑙𝑜𝑔𝑏𝑎), then: T(n) = (𝑛𝑙𝑜𝑔𝑏𝑎 lgn) Case 3: if f(n) = (𝑛𝑙𝑜𝑔𝑏𝑎+) for some  > 0, and if af(n/b) ≤ cf(n) for some c < 1 and all sufficiently large n, then: T(n) = (f(n)) meghav@kannuruniv.ac.in
  • 21. Example 1 T(n) = 2T(n/2) + n a = 2, b = 2, log22 = 1 Compare 𝑛𝑙𝑜𝑔22 with f(n) = n  f(n) = (n)  Case 2  T(n) = (nlgn) meghav@kannuruniv.ac.in
  • 22. Example 2 T(n) = 2T(n/2) + n2 a = 2, b = 2, log22 = 1 Compare n with f(n) = n2  f(n) = (n1+) Case 3  verify regularity cond. a f(n/b) ≤ c f(n)  2 n2/4 ≤ c n2  c = ½ is a solution (c<1)  T(n) = (n2) meghav@kannuruniv.ac.in
  • 23. Examples 3 T(n) = 2T(n/2) + a = 2, b = 2, log22 = 1 Compare n with f(n) = n1/2  f(n) = O(n1-) Case 1  T(n) = (n) n meghav@kannuruniv.ac.in
  • 24. Examples T(n) = 3T(n/4) + nlgn a = 3, b = 4, log43 = 0.793 Compare n0.793with f(n) = nlgn f(n) = (nlog 4 3+ ) Case 3 Check regularity condition: 3(n/4)lg(n/4) ≤ (3/4)nlgn = c f(n), c=3/4 T(n) = (nlgn) meghav@kannuruniv.ac.in
  • 25. Assignment Solve the following recurrence using Master’s method 1. T(n) = 9T(n/3)+n 2. T(n) = 16T(n/4)+n3 3. T(n) = 8T(n/2)+n2 4. T(n) = 2T(n/2)+n meghav@kannuruniv.ac.in