Master MethodProof Part 1 Design and Analysis of Algorithms I... Level logbn a braches Base cases size 1ti... Work at a Single LevelTotal work at level j [ignoring work in recursive call
Trang 1Master Method
Proof (Part 1)
Design and Analysis
of Algorithms I
Trang 2The Master Method
Trang 3Nextcore AI -Gopal Shangari
Assume : recurrence is
I
II
And n is a power of b
(general case is similar, but more tedious
ti
Idea : generalize MergeSort analysis
(i.e., use a recursion tree ti
( For some constant c ti
Trang 5THE RECURSION TREE
Level 0
Level 1
.
.
.
.
Level logbn
a braches
Base cases (size 1ti
Trang 6Work at a Single Level
Total work at level j [ignoring work in recursive calls]
Trang 7Total Work
Summing over all levels j = 0,1,2,…, logbn :
Total
work
Trang 8Nextcore AI -Gopal Shangari
Master Method Intui3on for
the 3 Cases
Design and Analysis
of Algorithms I
Trang 9Nextcore AI -Gopal Shangari
HOW TO THINK ABOUT (*)
Interpreta3on
a = rate of subproblem prolifera3on (RSP)
bd = rate of work shrinkage (RWS)
(per subproblem)
Trang 10Which of the following statements are true? (Check all that apply.ti
Trang 11[might expect O(# leavesti]
Nextcore AI - Gopal Shangari
INTUITION FOR THE 3 CASES
1 RSP = RWS => Same amount of work each level (like
Merge
Sortti
[expect O(ndlog(nti]
2 RSP < RWS => less work each level => most work at the
O(ndti]
3 RSP > RWS => more work each level => most work at
the leaves
Trang 12Master Method
Proof (Part II)
Design and Analysis
of Algorithms I
Trang 13THE STORY SO FAR/CASE 1
Nextcore AI -Gopal Shangari
[ end Case 1 ]
=1
= (logbn + 1)
= 1 for all j
Trang 14Basic Sums Fact
, we have
Proof : by induction (you check)
Upshot:
1 If r<1 is constant, RHS is <=
2 If r>1 is constant, RHS is <=
= a constant
Nextcore AI -Gopal Shangari
Trang 15<= a constant ( independent of nti
[ by basic sums fact ]
[ total work dominated by top level ]
CASE 2
Nextcore AI -Gopal Shangari
:= r
Trang 16Nextcore AI -Gopal Shangari
•
<= constant * largest term
:= r > 1
Trang 17The number of levels of the recursion tree.
The number of nodes of the recursion tree.
The number of edges of the recursion tree.
Level 0
Level 1
Level logbn
# of leaves =
Trang 18[End Case 3]
More intuiKve Simpler to apply
Trang 19The Master Method
•