简体   繁体   English

如果一个函数接受两个数组,并且该函数将在O(n)中一次迭代每个数组

[英]if a function accepts two arrays and that function will iterate each array one time is in O(n)

If a function accepts two arrays and that function will iterate each array one time is in O(n) 如果一个函数接受两个数组,并且该函数将在O(n)中一次迭代每个数组

a = [2 elements] // can be any length
b = [1000000 elements] // can be any length

function(a,b){
// NOT nested
  loop a  // O(n)
  loop b // O(n)
}

Is this O(n+n) but we simplify to O(n) ? 这是O(n+n)但我们简化为O(n)吗?

Time-complexity classes are a representation of how the time grows as n approaches infinity. 时间复杂度类表示随着n接近无穷大,时间如何增长。 Thus, you can multiply them by any finite constant k, and the time complexity will remain the same (because ultimately it won't matter for incredibly large values of n) 因此,您可以将它们乘以任何有限常数k,并且时间复杂度将保持不变(因为最终,对于非常大的n值而言,这无关紧要)

Take a look here: https://en.wikipedia.org/wiki/Big_O_notation You can see the relevant section under "Multiplication by a constant" 在这里看看: https : //en.wikipedia.org/wiki/Big_O_notation您可以在“乘以常数”下看到相关部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM