Algorithm O(logn)与算法关系

Algorithm O(logn)与算法关系,algorithm,complexity-theory,discrete-mathematics,big-theta,Algorithm,Complexity Theory,Discrete Mathematics,Big Theta,我仍然不能很好地分析O(logn)算法 所以如果有一个嵌套的for循环,它的内部循环增加/减少乘或除,那么它就是大θ(logn),它的基数是除以或乘多少 例如: for(int i=0;i<n;i++) { for(int j=1; j<n; j*=5) ... this is Big-theta(logn) with base 5 since it is multiplied by 5? for(int i=n;i>0;i--) { for(int j=i; j>0

我仍然不能很好地分析O(logn)算法

所以如果有一个嵌套的for循环,它的内部循环增加/减少乘或除,那么它就是大θ(logn),它的基数是除以或乘多少

例如:

for(int i=0;i<n;i++) {
for(int j=1; j<n; j*=5) ...

this is Big-theta(logn) with base 5 since it is multiplied by 5?
for(int i=n;i>0;i--) {
for(int j=i; j>0; j/=10) ...

this is 
Big-theta(logn) with base 10 since it is divided by 10?
我的意思是,我理解对了吗

另一个问题:

for(int i=0;i<n;i++) {
for(int j=1; j<n; j*=5) ...

this is Big-theta(logn) with base 5 since it is multiplied by 5?
for(int i=n;i>0;i--) {
for(int j=i; j>0; j/=10) ...

this is 
Big-theta(logn) with base 10 since it is divided by 10?

大θ(logn)仅适用于嵌套循环?(for循环中的for循环)

。我们可以从一个简单for循环的示例开始

考虑以下for循环:

for(int i=1;i<=m;i++)
{
    //....
}

这个系列是。现在我们有了一个方程,可以求出级数的第n项,
{a(n)=a(1)+(n-1)*d}
。这里
d=1,a(1)=1
现在我们需要找到最大值n,这样
a(n)在第二个例子中,内循环是无限循环。@SanketMakani抱歉,修改了。@Miku但是上面两个循环的整体复杂度是大θ(n*log(n))。只有内部循环的复杂度是大θ(logn)。
for(int j=1; j<n; j*=5)...
a(n) = a(1)*(r^(n-1))
m = 1*(5^(n-1))
m = 5^(n-1)
Now take log of base 5 on both side
log (m) = (n-1) //log is of base 5
n = log(m)+1 
for(int i=1;i<=n;i*=2)