/**
* @author Zsx
* 时间复杂度
* O(1) < O(log2n) < O(n) < O(nlog2n) < O(n^2) < O(n^3) < O(n^k) < O(2^n) < O(n!)
* @Time 2021/6/16 21:50
*/
public class TimeComplexity {
/**
* 举例说明
*
* @param args
*/
public static void main(String[] args) {
//时间复杂度 = O(1)
int a = 0;
int b = 1;
//时间复杂度 = O(log2n)
int i = 1;
while (i < n) {
i = i * 2;
}
//时间复杂度 = O(n)
for (int j = 0; j < n; j++) {
j++;
}
//时间复杂度 = O(nlog2n)
for (int j = 0; j < n; j++) {
int i = 1;
while (i < n) {
i = i * 2;
}
}
//时间复杂度 = O(n^2)
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
xxx
}
}
//时间复杂度 = O(n^3)
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
for (int l = 0; l < n; l++) {
xxx
}
}
}
}
}
07-22