时间复杂度和theta算法

时间:2020-10-28 16:08:13

标签: algorithm time time-complexity big-o

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 个答案:

答案 0 :(得分:0)

完全根据您的分析,时间复杂度为:

(1 +‌ n + n^2) in \Theta(n^2) and O(n^2)

n^2用于嵌套循环。