问题
In my algorithm class we are discussing big O notation and I am stuck proving this example problem:
Prove f(n) = 3n lg n + 10n + lg n + 20 = O(n lg n)
Details will be appreciated.
回答1:
Big O
notation is an asymptotic notation and it's all about approximation of cases (worst, best and mid one).
In your example, nlgn
grows faster than both n
and lgn
, moreover constant values are not relevant and can be ignored in such an approximation.
Because of that, it follows that the complexity is O(nlgn)
.
回答2:
All you need to prove is that for some M and X0:
M n lg n >= 3n lg n +10n + lg n + 20 for all n greater than X0
4 is pretty easy for M
I'm sure you can compute some x0 for which the above inequality holds and then easily show that it remains true for all n greater than X0
It helps to simplify the above after substituting in the 4 to
(n-1)lg n >= 10n + 20
Once any n is big enough, it should be clear that lg n > 1, so any increase in n beyond that increase the right by 1 and the left by more than 1.
来源:https://stackoverflow.com/questions/34274287/how-to-prove-big-o-notation