-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOComplexity.java
More file actions
66 lines (54 loc) · 1.34 KB
/
OComplexity.java
File metadata and controls
66 lines (54 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.liang.algorithm;
/**
* 时间复杂度伪代码
*
* @author LiaNg
* @date 2020/4/25 19:47
*/
public class OComplexity {
public static void main(String[] args) {
Integer n = Integer.MAX_VALUE;
// 时间复杂度为 O(1)
int i = 1;
int j = 2;
int sum = i + j;
// 时间复杂度为 O(logn)
int left = 0;
int right = n;
while (left < right) {
int mid = left + (right - left) / 2;
//条件判断
if (1 == 1) {
left = mid + 1;
} else {
right = mid - 1;
}
}
// 时间复杂度为 O(c^n)
int c = 2;
for (int k = 0; k < Math.pow(c,n); k++) {
// TODO
}
// 时间复杂度为 O(n)
for (int k = 0; k < n; k++) {
// TODO
}
// 时间复杂度为 O(n^2)
for (int k = 0; k < n; k++) {
for (int l = 0; l < n; l++) {
// TODO
}
}
int[] nums = new int[n];
backtrack(nums, 0, n);
}
public static void backtrack(int[] nums, int i, int n) {
for (int j = i; j < n; ++j) {
if (i != j) {
// TODO
} else {
backtrack(nums, i + 1, n);
}
}
}
}