Asymptotic Complexity of Logarithms and Powers

前端 未结 3 1715
抹茶落季
抹茶落季 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.

提交回复
热议问题