algorithm - 算法运行时间T(n)

标签 algorithm

我已经分析了以下算法的运行时间是分析theta但它的运行时间可能是Big O吗?

                               Cost             Time
1.  for i ←1 to n                c1             n   
2.      do for j ← i to n        c2             n
3.          do k ← k+ j          c3             n-1
T(n) = c1n +c2n+c3(n-1)
     = C1n+C2n+C3(n-1)
     = n(C1+C2)+n-1
     = n+n-1
Or T(n) = Ө(n)
So running time is Ө(n)

最佳答案

您的循环将按如下方式继续(众所周知的算术 progression 公式):

enter image description here

-也可以估计为enter image description here因为 big-O 给出了多数估计。

关于algorithm - 算法运行时间T(n),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18901787/

相关文章:

algorithm - 优化找到有毒 cookie 的天数

algorithm - 大数的数学表示?

algorithm - 中介中心性布兰德斯算法

algorithm - 求所有 n 位二进制数,其中 r 个相邻数字为 1

algorithm - 不相交数据结构中森林的组合

algorithm - 如何用卷积解决精确模式匹配

algorithm - 在UTF :s without intermediate encoding之间转换

c++ - 在循环排序算法中,我正在寻找一种情况,在这种情况下我们观察到算法的不稳定特性

algorithm - 如何找到字符串可能具有的对的最大值?

algorithm - 最短路径的最大流算法?