问题
I'm currently trying to solve this relation with the master theorem:
T(n) = 2T(n/4) + log n
I already figured out that a = 2 and b = 4, but I'm confused about the log n.
My script say: c(n) (which would be log n here) is element of 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.
However, due to the fact that it's log n here, I'm not sure about its Big O notation.
I mean I could probably say it's element of O(n1/2), which would then lead to case two, where a and b^d are the same, but it's also element of O(n1), which would then be another case again.
回答1:
One useful fact is that for any ε > 0, we know that
log n = O(nε).
We also know that
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:
S(n) = 2S(n / 4) + nε
Let's use the Master Theorem here. We have a = 2, b = 4, and d = ε. We need to reason about logb a = log4 2 = 1/2 and how that relates to d = ε. Let's make ε small - say, let's pick ε = 0.000001. Then we have logb a < d, so the Master Theorem says that the runtime would be
O(nlogb a) = O(n1/2).
Next, consider this recurrence relation:
R(n) = 2R(n / 4) + 1
This recurrence lower-bounds your recurrence. Using the Master Theorem tells us that R(n) = Ω(n1/2) as well.
Overall, we see that your recurrence is O(n1/2) and Ω(n1/2) by upper- and lower-bounding your recurrence by larger and smaller recurrences. Therefore, even though the Master Theorem doesn't apply here, you can still use the Master Theorem to claim that the runtime will be Θ(n1/2).
Hope this helps!
来源:https://stackoverflow.com/questions/30987299/solving-master-theorem-with-log-n-tn-2tn-4-log-n