简体   繁体   English

当有两个单独的for循环时,如何找到Big O.

[英]How to find the Big O when there are two separate for loops

我知道如何为“for循环”和嵌套的“for循环”找到Big O,但是当我们有两个for循环,而不是嵌套但在同一个函数中有两个独立的for循环时会发生什么。

It just gets added. 它只是被添加。

See for eg : 参见例如:

for(i=0;i<n;i++)
    //statements

for(i=0;i<m;i++)
    //statements

So the total complexity is O(m+n). 因此总复杂度为O(m + n)。

lets say m=3n then its O(4n) which is O(n) only . 比方说m = 3n然后是O(4n),它只是O(n)。

let m = n^2 设m = n ^ 2

then its O(n^2+n) which is O(n^2) 那么它的O(n ^ 2 + n)是O(n ^ 2)

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

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