Having different loops inside of a function doesn't cause the BigOh to be multiplied together, right?
Example:
function() {
for(int i = 0; i < n; i++) {
//logic here
}
for(int i = 0; i < n; i++) {
//logic here
}
}
Having different loops inside of a function doesn't cause the BigOh to be multiplied together, right?
Example:
function() {
for(int i = 0; i < n; i++) {
//logic here
}
for(int i = 0; i < n; i++) {
//logic here
}
}
This is pretty well discussed (i.e. General Reference) but yes you are correct, the function you have in your question would be O(n).
Technically O(2n) which gets reduced to O(n)
Yes it's still O(n) because you would have O(n+n) which is O(2n) but we can ignore the 2 because it has negligible effect. But if you had
for (...){
for(...){
//code here
}
}
Then it would be O(n^2)