algorithm - 程序的运行时间

标签 algorithm runtime

for i from 1 to n*n do
 j=n
 while j > 0 do
   j--

如果我们使用求和,我发现运行时间严格为 $$\Theta(n^6)$$,但我不确定这是否正确。有什么指点吗?

最佳答案

运行时间的计算是这样的:

  • 第一个 for 循环 for i from 1 to n*n do 总共迭代 n*n 次。
  • 第二个while循环
    j=n 当 j > 0 时 j--
    总共迭代 n 次。

因此,总运行时间相当于 O(n*n)*O(n) = O(n^3)

关于algorithm - 程序的运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48799268/

相关文章:

.net - Silverlight 限制/限制列表

delphi - 如何在delphi中运行时将图表系列添加到dbchart

algorithm - 运行空间分析

c++ - 顺时针和逆时针旋转数组的有效方法

algorithm - 数字子集的总和

c - C语言数据结构与算法分析第2章总结

java - Java 中 Public 与 Private 的运行时性能

exception - Swift 中的运行时错误处理

c++ - 实现二进制搜索猜谜游戏

algorithm - 德劳内 : Triangulate two point sets with the best fitting mesh