问题
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