+ 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

27th Jul 2020, 7:43 AM
Andrei I
Andrei I - avatar
1 Resposta
+ 5
O(n) +O(n) =2*O(n) 2 is constant hence total is O(n)
27th Jul 2020, 7:46 AM
Aayush $aini
Aayush $aini - avatar