时间复杂度和theta算法
time complexity and theta algorithm
x=x+1 ; // constant time
// executes n times
for (i≡ 1 ; i<≡ n; i++
m=m+2 // constant time
//outer loop executes n times
for (i=1; i<=n; i++) {
// inner loop executed n times
for (j=1; j<=n; j++)
k=k+1; // constant time
}
这段代码的时间复杂度函数是多少,theta Θ-算法是什么?
(对不起我的英语)
完全根据你的分析,时间复杂度是:
(1 + n + n^2) in \Theta(n^2) and O(n^2)
n^2
用于嵌套循环。
x=x+1 ; // constant time
// executes n times
for (i≡ 1 ; i<≡ n; i++
m=m+2 // constant time
//outer loop executes n times
for (i=1; i<=n; i++) {
// inner loop executed n times
for (j=1; j<=n; j++)
k=k+1; // constant time
}
这段代码的时间复杂度函数是多少,theta Θ-算法是什么? (对不起我的英语)
完全根据你的分析,时间复杂度是:
(1 + n + n^2) in \Theta(n^2) and O(n^2)
n^2
用于嵌套循环。