algorithm - 使用 Big O Notation,这个算法的正确标签是什么?

标签 algorithm for-loop nested time-complexity big-o

我很好奇。使用 Big-O Notation 来描述它的正确方法是什么?

var prices = [100, 180, 260, 590, 40, 310, 535, 10, 5, 3];
var biggest_profit = 0;
  
for (var i = 0; i < prices.length; i++) {
    var first_price = prices[i];
  
    for (var j = i + 1; j <= prices.length; j++) {
      // do something here
    }
}
  

这是让我失望的一点:

j = i + 1

每次我们遍历 i 时,j 都会变得越来越短。

这种模式在大 O 表示法中的正确名称是什么?

最佳答案

您可以使用 Sigma 表示法来计算内循环的访问次数(“在这里做点什么”)

enter image description here

其中 (*) 来自 summation rule made famous by the rumour that Gauss once derived it on-the-spot as a young student .

关于algorithm - 使用 Big O Notation,这个算法的正确标签是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807238/

相关文章:

algorithm - 除了 Levenshtein 之外,用于有序词集和后续聚类的更好的距离度量

javascript - for循环和执行顺序

c - 学生评分数组程序中的持续段错误

javascript - JS : convert array objects to dot string

python - 从一组边有效地创建和存储所有大小的所有 "valid"边组合

python-解决圆 table session (ZCO,2012)

C++ - 知道类型/类是否嵌套?

ruby - 事件记录 3 选择嵌套表

algorithm - 找到最高塔的最小可能高度

C++ - for 循环中的条件未按我认为应该的方式进行评估