O(n^2) vs O (n(logn)^2)

后端 未结 6 2132
悲哀的现实
悲哀的现实 2021-02-01 23:18

Is time complexity O(n^2) or O (n(logn)^2) better?

I know that when we simplify it, it becomes

O(n) vs O((logn)^2)
6条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 23:23

    For each constant k asymptotically log(n)^k < n.

    Proof is simple, do log on both sides of the equation, and you get:

    log(log(n))*k < log(n)
    

    It is easy to see that asymptotically, this is correct.


    Semantic note: Assuming here log(n)^k == log(n) * log(n) * ... * log(n) (k times) and NOT log(log(log(...log(n)))..) (k times) as it is sometimes also used.

提交回复
热议问题