什麼是嵌套循環的時間複雜度如下所示的時間複雜度:如何找到的嵌套的循環
1)
for (int i = 1; i <=n; i += 2) {
for (int j = 1; j <=n; j += 2) {
// some O(1) expressions
}
}
2)
for (int i = 1; i <=n; i += 3) {
for (int j = 1; j <=n; j += 3) {
// some O(1) expressions
}
}
一般:
for (int i = 1; i <=n; i += c) {
for (int j = 1; j <=n; j += c) {
// some O(1) expressions
}
}
這是真的嗎下列?
O(nc)