Asymptotic Complexity of Logarithms and Powers

前端 未结 3 1709
抹茶落季
抹茶落季 2020-12-18 15:53

So, clearly, log(n) is O(n). But, what about (log(n))^2? What about sqrt(n) or log(n)--what bounds what?

There\'s a family of comparisons like this:
n^a versu

相关标签:
3条回答
  • 2020-12-18 15:59

    log(n)^a is always O(n^b), for any positive constants a, b.

    Are you looking for a proof? All such problems can be reduced to seeing that log(n) is O(n), by the following trick:

    log(n)^a = O(n^b) is equivalent to: log(n) = O(n^{b/a}), since raising to the 1/a power is an increasing function. This is equivalent to log(m^{a/b}) = O(m), by setting m = n^{b/a}. This is equivalent to log(m) = O(m), since log(m^{a/b}) = (a/b)*log(m).

    You can prove that log(n) = O(n) by induction, focusing on the case where n is a power of 2.

    0 讨论(0)
  • 2020-12-18 16:10

    I run into these comparisons a lot (...) Hints for tactics for solving the general case?

    As you as about general case and that you following a lot into such questions. Here is what I recommend :

    Use limit definition of BigO notation, once you know:

    f(n) = O(g(n)) iff limit (n approaches +inf) f(n)/g(n) exists and is not +inf
    

    You can use Computer Algebra System, for example opensource Maxima, here is in Maxima documentation about limits .

    For more detailed info and example - check out THIS answer

    0 讨论(0)
  • 2020-12-18 16:26
    log n -- O(log n)
    sqrt n -- O(sqrt n)
    n^2 -- O(n^2)
    (log n)^2 -- O((log n)^2)
    

    n^a versus (log(n))^b

    You need either bases or powers the same. So use your math to change n^a to log(n)^(whatever it gets to get this base) or (whatever it gets to get this power)^b. There is no general case

    0 讨论(0)
提交回复
热议问题