CSE101: Algorithm Design and Analysis
Russell Impagliazzo Sanjoy Dasgupta Ragesh Jaiswal (Thanks for slides: Miles Jones)
Week-06 Lecture 22: Divide and Conquer (Master Theorem)
CSE101: Algorithm Design and Analysis Russell Impagliazzo Sanjoy - - PowerPoint PPT Presentation
CSE101: Algorithm Design and Analysis Russell Impagliazzo Sanjoy Dasgupta Ragesh Jaiswal (Thanks for slides: Miles Jones) Week-06 Lecture 22: Divide and Conquer (Master Theorem) Master Theorem How do you solve a recurrence of the form
Russell Impagliazzo Sanjoy Dasgupta Ragesh Jaiswal (Thanks for slides: Miles Jones)
Week-06 Lecture 22: Divide and Conquer (Master Theorem)
Consider the summation !
!"# $
π ! It behaves differently for different values of π .
Consider the summation !
!"# $
π ! It behaves differently for different values of π . If π < 1 then this sum converges. This means that the sum is bounded above by some constant π. Therefore ππ π < 1, π’βππ !
!"# $
π ! < π πππ πππ π π‘π !
!"# $
π ! Ο΅ π(1)
Consider the summation !
!"# $
π ! It behaves differently for different values of π . If π = 1 then this sum is just summing 1 over and over n times. Therefore ππ π = 1, π’βππ !
!"# $
π ! = !
!"# $
1 = π + 1 Ο΅ π(π)
Consider the summation !
!"# $
π ! It behaves differently for different values of π . If π > 1 then this sum is exponential with base π . ππ π > 1, π’βππ !
!"# $
π ! < ππ $ πππ πππ π, π‘π !
!"# $
π ! Ο΅ π π $ π > π π β 1
Consider the summation !
!"# $
π ! It behaves differently for different values of π . !
!"# $
π ! Ο΅ 9 π 1 ππ π < 1 π π ππ π = 1 π π $ ππ π > 1
Size π Size π/π Size π/π% Size 1 Depth log& π 1 subproblem π subproblems π% subproblems π'()! $ subproblems
After π levels, there are π! subproblems, each
So, during the πth level of recursion, the time complexity is π
$ &" *
π! = π π!
$ &" *
= π π* π π*
!
After π levels, there are π! subproblems, each of size π/π!. So, during the πth level, the time complexity is π
$ &" *
π! = π π!
$ &" *
= π π* π π*
!
After log& π levels, the subproblem size is reduced to 1, which usually is the size
So the entire algorithm is a sum of each level. π π = π π* !
!"# '()! $
π π*
!
π π = π π" &
#$% &'(! )
π π"
#
Case 1: π < π" Then we have that
* +" < 1 and the series converges to a constant so
π π = π π"
π π = π π" &
#$% &'(! )
π π"
#
Case 2: π = π" Then we have that
* +" = 1 and so each term is equal to 1
π π = π π" log+ π
π π = π π" &
#$% &'(! )
π π"
#
Case 2: π > π" Then the summation is exponential and grows proportional to its last term
* +" &'(! )
so π π = π π" π π"
&'(! )
= π π&'(! *
Top-heavy Steady-state Bottom-heavy
π π Ο΅ π π* ππ π < π* π π* log π ππ π = π* π π'()! + ππ π > π*
π π Ο΅ π π* ππ π < π* π π* log π ππ π = π* π π'()! + ππ π > π*
3)
xL xM yL yM xR yR
π π Ο΅ π π* ππ π < π* π π* log π ππ π = π* π π'()! + ππ π > π*
234(,167) 234 1
!"# $%&' !"# %