大θ分析算法

时间:2019-03-02 21:52:52

标签: time-complexity big-o complexity-theory

enter image description here

我不得不说这三种算法的时间复杂性。 有人可以看到他们是否正确吗?

我也不确定如何找到theta?

我知道theta是big-O和Omega的平均值。但是我认为在分析代码并以big-O表示法编写代码时,它基本上是相同的。

1 个答案:

答案 0 :(得分:0)

第一个似乎正确,以下说明,Θ符号的定义如下

Θ(g(n)) = {f(n) : there exists c1,c2,n0 such that
                 0 <= c1*g(n) <= f(n) <= c2*g(n) given c1,c2,n0 > 0}

在第一段中,我们应该寻找f(n)

f(n)= n/3 + n/5 = 8/15*n

如果我们假设c1 = 0.5,c2 = 2,n0 = 15(因为3和5都可除),则找到g(n) 那么下面将是这种情况

when n=15, 0<=c1g(n)<=f(n)<=c2g(n)  =>  0<=c1g(n)<=1*8/15*15<=c2g(n)  =>  0<=0.5*g(n)<=8<=2*g(n)
when n=30 0<=0.5g(n)<=16<=2g(n)
when n=90 0<=0.5g(n)<=48<=2g(n) ...so on

when n=17 0<=0.5g(n)<=9<=2g(n)
when n=20 0<=0.5g(n)<=10<=2g(n)

因此,g(n)= n似乎是适当的选择,并且由于我们可以证明c1,c2和n0的一种组合说明定义是正确的,因此 g(n)= n 是可以接受的答案