Why can we assume that for T(n) = 2T(n/2) + theta(1), n is a power of 2?

回眸只為那壹抹淺笑 提交于 2019-12-11 13:07:44

问题


Lately I have been interested in algorithms and I have been watching a video series published by MIT. I encountered some problems regarding recurrence though.

https://www.youtube.com/watch?v=-EQTVuAhSFY

The attached link is the source of the video. At 07:10, the professor mentioned that it's fine to use T(n/2) in T(n) = 2T(n/2) + theta(1) due to a certain theorem, despite that it would be more accurate to use T(the floor of n/2) or T(the ceiling of n/2).

What exactly is this theorem? Actually I'm kind of confused because n/2 might not generate the base case input for some n.

e.g. some initial input that is not a power of 2.


回答1:


Great question. I'm sure you learnt about the Big-O in that lesson, so I shall not elaborate on that. (My explanation will use O(N) which for the ease of explanation, can be assumed as the same as theta(N), but they are different!)

The important part of Big-O (and theta) is SIGNIFICANCE. For example, O(N) will always be more significant than O(1), even if it was 99999*O(1) vs O(N).

So, what your professor is trying to say is that when you do n/2, you do NOT have to floor or ceiling it because the extra bit that you do away with is not significant. What you are dealing with is runtime in a Big-O scenario, which does not care about the nitty bitty details. We are assuming N is HUGE, and your little extra bit of time spent trying to floor or ceiling N is never comparable.

Basically for Big-O, you want sweeping generalizations, which thankfully means you can assume n is a power of 2!



来源:https://stackoverflow.com/questions/30995094/why-can-we-assume-that-for-tn-2tn-2-theta1-n-is-a-power-of-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!