简体   繁体   English

用log n求解主定理:T(n)= 2T(n / 4)+ log n

[英]Solving master theorem with log n: T(n) = 2T(n/4) + log n

I'm currently trying to solve this relation with the master theorem: 我目前正在尝试用主定理解决这种关系:

T(n) = 2T(n/4) + log n T(n)= 2T(n / 4)+对数n

I already figured out that a = 2 and b = 4, but I'm confused about the log n. 我已经知道a = 2和b = 4,但是我对log n感到困惑。

My script say: c(n) (which would be log n here) is element of Big O(n^d). 我的脚本说:c(n)(此处将为log n)是Big O(n ^ d)的元素。

If I can figure out my d here, I would compare a and b^d to find out my master theorem case. 如果我能在这里找到我的d,我将比较a和b ^ d以找出我的主定理案例。

However, due to the fact that it's log n here, I'm not sure about its Big O notation. 但是,由于它在此处登录为n,因此我不确定其Big O表示法。

I mean I could probably say it's element of O(n 1/2 ), which would then lead to case two, where a and b^d are the same, but it's also element of O(n 1 ), which would then be another case again. 我的意思是我可能会说这是O(n 1/2 )的元素,这将导致第二种情况,其中a和b ^ d是相同的,但它也是O(n 1 )的元素,那么它将是又是另一种情况。

One useful fact is that for any ε > 0, we know that 一个有用的事实是,对于任何ε> 0,我们都知道

log n = O(n ε ). log n = O( )。

We also know that 我们也知道

log n = Ω(1) log n =Ω(1)

Let's see if this tells us anything. 让我们看看这是否告诉我们什么。 We know that your recurrence is bounded from above by this one for any ε > 0: 我们知道,对于任何ε> 0,您的复发都受此限制。

S(n) = 2S(n / 4) + n ε S(n)= 2S(n / 4)+

Let's use the Master Theorem here. 让我们在这里使用主定理。 We have a = 2, b = 4, and d = ε. 我们有a = 2,b = 4,和d =ε。 We need to reason about log b a = log 4 2 = 1/2 and how that relates to d = ε. 我们需要推理出log b a = log 4 2 = 1/2以及与d =ε的关系。 Let's make ε small - say, let's pick ε = 0.000001. 让我们将ε减小-例如,让我们选择ε= 0.000001。 Then we have log b a < d, so the Master Theorem says that the runtime would be 然后我们有log b a <d,所以主定理说运行时间为

O(n log b a ) = O(n 1/2 ). O(n log b a )= O(n 1/2 )。

Next, consider this recurrence relation: 接下来,考虑以下递归关系:

R(n) = 2R(n / 4) + 1 R(n)= 2R(n / 4)+ 1

This recurrence lower-bounds your recurrence. 这种复发会降低您的复发率。 Using the Master Theorem tells us that R(n) = Ω(n 1/2 ) as well. 使用主定理告诉我们,R(n)=Ω(n 1/2 )也是。

Overall, we see that your recurrence is O(n 1/2 ) and Ω(n 1/2 ) by upper- and lower-bounding your recurrence by larger and smaller recurrences. 总体而言,我们看到您的复发率是O(n 1/2 )和Ω(n 1/2 ),上下限将您的复发率分为较大和较小的复发率。 Therefore, even though the Master Theorem doesn't apply here, you can still use the Master Theorem to claim that the runtime will be Θ(n 1/2 ). 因此,即使Master Theorem在这里不适用,您仍然可以使用Master Theorem声明运行时间为Θ(n 1/2 )。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM