比较O(logn)与O((logn)^ 2)的时间复杂度

时间:2019-11-26 09:52:30

标签: algorithm math time-complexity big-o

时间复杂度O(logn)O((logn)^2)相同吗? 你能证明吗?

3 个答案:

答案 0 :(得分:1)

使用Big-O的定义,我们可以证明O(logn)与O((logn)^ 2)不同。

enter image description here

答案 1 :(得分:0)

我们如何比较O(F(n))O(G(n))?我们计算 limit

  lim (F(n) / G(n))
    n -> +Inf

如果3是,则我们有lim个案例

  1. 0:然后是O(F(n)) < O(G(n))
  2. 一些正有限值:然后是O(F(n)) = O(G(n))
  3. Infinity :然后是O(F(n)) > O(G(n))

对于F(n) = log(n)G(n) = log(n)**2,我们有

  lim (F(n) / G(n)) = lim (log(n) / log(n)**2) = lim (1 / log(n)) = 0
    n -> +Inf           n -> +Inf                  n -> +Inf

所以我们有第一种情况,因此O(log(n)) < O(log(n)**2)

答案 2 :(得分:0)

这是一张表,比较n和logn和(logn)^ 2。请注意(logn)^ 2如何更快地增长。

作为一个(人工的)示例,假设您对某种类型的大数进行了素性检验。如果您有logn算法,则可以处理比(logn)^ 2算法大得多的n。例如。当您进行加密时,会大量使用大量的数字。

__FUNCTION__