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

后端 未结 6 2131
悲哀的现实
悲哀的现实 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:31

    O(n(logn)^2) is better (faster) for large n!

    take log from both sides:

    Log(n^2)=2log(n)

    Log(n(logn)^2)=Log(n)+2log(Log(n))=Log(n)+2log(Log(n))

    lim n--> infinity [(Log(n)+2log(Log(n)))/2log(n)/]=0.5 (use l'Hôpital's rule)(http://en.wikipedia.org/wiki/L'H%C3%B4pital's_rule)]

提交回复
热议问题