算法:程序运行的次数
O(1):常数复杂度
printf("hello world");
O(log n):对数复杂度
for (int i &#61; 1; i < n; i &#61; i * 2)
{printf(hello world\n);
}
O(n):线性时间复杂度
for(int i &#61; 1; i < n; i&#43;&#43;)
{ printf("hello world\n");
}
O(n^2):平方
for(int i &#61; 1; i < n; i&#43;&#43;)
{ for (int j &#61; 1; j < n; j&#43;&#43;) { printf("hello world\n");}
}
O(n^3):立方
for(int i &#61; 1; i < n; i&#43;&#43;)
{ for (int j &#61; 1; j < n; j&#43;&#43;) { for (int j &#61; 1; j < n; j&#43;&#43;){printf("hello world\n");} }
}
O(2^n):指数
#include
for(int i &#61; 1; i < pow(2 , n); i&#43;&#43;)
{ printf("hello world\n");
}
O(n!):阶乘
for(int i &#61; 1; i <(n的阶乘); i&#43;&#43;)
{ printf("hello world\n");
}
PS&#xff1a;只看最高复杂度的运算