How do I determine the big O for my nested for loop?

45 views Asked by At

I have a nested for loop. I am aware that a nested for loop is of O(n2). I have some code that runs in the for loops, but it is conditional, as it only runs if conditions are met. Is that to be factored into the big O? Or is it so small compared the scaling of O(n2) that it is meaningless?

1

There are 1 answers

0
Pavan On

It does not matters whether your meets the conditions.If you are thinking about big O notation then you should consider the worst case scenario where your code will meet all conditions and execute it.

below is the link that might help you,

https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/