时间复杂度O
1.线性阶
1 2 3 4 5 6
| int i;
for (i = 0; i < n; ++i) ;
|
2.对数阶
1 2 3 4 5 6
| int i = 1;
while (i < n) i *= 2;
|
3.平方阶
1 2 3 4 5 6 7 8 9
| int i, j;
for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) ; }
|
1 2 3 4 5 6 7 8 9
| int i, j;
for (i = 0; i < n; ++i) { for (j = i; j < n; ++j) ; }
|
Welcome to my other publishing channels