OPY-bbt / OPY-bbt.github.io

my webpage
https://opy-bbt.github.io/
0 stars 0 forks source link

时间复杂度 #10

Open OPY-bbt opened 5 years ago

OPY-bbt commented 5 years ago

表示代码执行时间随数据规模增长的变化趋势,所以,也叫作渐进时间复杂度

代码的时间复杂度等于量级最大的那段代码的复杂度

最好,最坏,均摊时间复杂度

function find(num) {
  for(var i = 0; a < arr.length; i++) {
     if (arr[i] === num) { return i; }
  }
  return -1;
}

最好时间复杂度O(1) 最坏时间复杂度O(n) 平均时间复杂度O(n) = (1+2+···+n+n)/(n+1) ~ O(n) 均摊时间复杂度,使用情况较少,仅仅适用于在两种时间复杂度以某种规律交替出现的情况下