+ 1
Time complexity related question
If we have 2 for loops both with a complexity of O(n) one after the other not nested what is the complexity of the whole function. I've been told that is still O(n) but shouldn't it ne O(2n) because we're looping in the array two times
1 Odpowiedź
+ 5
O(n) +O(n) =2*O(n)
2 is constant hence total is O(n)