Recursion Tree Method
Give开发者_JAVA技巧n Equation: T(n) = T(n/4) + T(n/2) + n^2
Model of Tree:
T(n) -- Level 1
/ \
T(n/4) T(n/2) -- Level 2
/ \ / \
T(n/16) *T(n/8) T(n/4) *T(n/8) -- Level 3
From Lecture of MIT Algorithm Class: http://www.youtube.com/watch?v=whjt_N9uYFI
Minute: 38:53
Question: How, What and Why 3rd level becomes n/8 ? What is the explicit equation to create recursion tree?
This isn't the homework question by the way.
The original tree is this:
T(n) = n^2 -> T(n/4)
-> T(n/2)
When you expand the first branch, you make a substitution n = n/4
so you get:
T(n/4) = (n/4)^2 -> T((n/4)/4)
-> T((n/4)/2)
= (n/4)^2 -> T(n/16)
-> T(n/8)
and similarly for the second branch, n = n/2
T(n/2) = (n/2)^2 -> T(n/8)
-> T(n/4)
so substituting these expansions back into T(n)
you get
T(n) = (n^2) -> (n/4)^2 -> T(n/16)
-> T(n/8)
-> (n/2)^2 -> T(n/8)
-> T(n/4)
精彩评论