简体   繁体   中英

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

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(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.

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 log b a = log 4 2 = 1/2 and how that relates to d = ε. Let's make ε small - say, let's pick ε = 0.000001. Then we have log b a < d, so the Master Theorem says that the runtime would be

O(n log b a ) = O(n 1/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) = Ω(n 1/2 ) as well.

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. 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 ).

Hope this helps!

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.

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