I have this recurrence:
W(n)= 2W(floor(n/2)) + 3
W(2)=2
My try is as follow:
the tree is like this:
W(n) = 2W(floor(n/2)) + 3
W(n/2) = 2W(floor(n/4)) + 3
W(n/4) = 2W(floor(n/8)) + 3
...
So, T(n) = 5n - 3 which belong to Theta(n)
my question is: Is that right?
Well, if you calculate W(4)
, you find W(4) = 2*W(2) + 3 = 2*2 + 3 = 7
, but 5*4 - 3 = 17
, so your result for T(n)
is not correct. It is close, though, there's just a minor slip in your reasoning (or possibly in a certain other place).
Edit: To be specific, your calculation would work if W(1)
was given, but it's W(2)
in the question. Either the latter is a typo or you're off by one with the height. (and of course, what Saeed Amiri said.)
I don't think it's exactly 5n-3
except n is 2 t , but your theta is right if you look at Master Theorem , there is no need to calculate it (but its good for startup):
assume you have:
T(n) = aT(n/b) + f(n), where a>=1, b>1 then:
for detail see wiki.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.