I know that complexity of two serial loops with the same number of iterations is O(n), as stated here, but what if the loops are based on different inputs? for example:
for(i;i<m;i++){
//code
}
for(y;y<n;y++){
//code
}
It would be O(m+n)?
I know that complexity of two serial loops with the same number of iterations is O(n), as stated here, but what if the loops are based on different inputs? for example:
for(i;i<m;i++){
//code
}
for(y;y<n;y++){
//code
}
It would be O(m+n)?
Yes, absolutely :)
The first loop, if it's not empty, has a multiple of m
operations.
The second loop has a multiple of n
operations.
Using both one after the other gives you O(m+n)
.