For loop 循环复杂性的嵌套和顺序
我正在做一些非常接近这段代码的事情:For loop 循环复杂性的嵌套和顺序,for-loop,time-complexity,big-o,discrete-mathematics,code-complexity,For Loop,Time Complexity,Big O,Discrete Mathematics,Code Complexity,我正在做一些非常接近这段代码的事情: for(int k=0; k<n; k++) { // n for(int a=0; a<k; a++) { // n/2 -> n (watch the a<k) ... // c } for(int i=0; i<n; i++) { // n for(int a=0; a&
for(int k=0; k<n; k++) { // n
for(int a=0; a<k; a++) { // n/2 -> n (watch the a<k)
... // c
}
for(int i=0; i<n; i++) { // n
for(int a=0; a<i; a++) { // n/2 -> n (watch the a<i)
... // c
}
for(int j=0; j<n; j++) { //n
... //c
}
}
}
for(int k=0;k在去掉for(a)之后,它仍然是O(n^3)
而且