[英]The Recurrence W(n)= 2W(floor(n/2)) + 3
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) 那么,T(n)= 5n - 3属于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. 那么,如果你计算W(4)
,你会发现W(4) = 2*W(2) + 3 = 2*2 + 3 = 7
,但是5*4 - 3 = 17
,所以你的结果是T(n)
不正确。 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. 编辑:具体来说,如果给出了W(1)
,你的计算就会起作用,但在问题中它是W(2)
。 Either the latter is a typo or you're off by one with the height. 要么是后者是一个错字,要么是一个身高的人。 (and of course, what Saeed Amiri said.) (当然,Saeed Amiri说过。)
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): 我认为它不是5n-3
除非n是2 t ,但是你的θ是正确的,如果你看一下Master定理 ,没有必要计算它(但它对启动有好处):
assume you have: 假设你有:
T(n) = aT(n/b) + f(n), where a>=1, b>1 then: T(n)= aT(n / b)+ f(n),其中a> = 1,b> 1则:
for detail see wiki. 详情请见维基。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.