I'm learning programming using YouTube and whatever I can find. I stumbled upon some Big O problems and I'm quite confused on one of them.
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++)
cout << i << " " << j << endl;
My first thought was that it is O(n2) because there are 2 for loops. Then I took a closer look and noticed that the inner for loop only goes from 0 to 2.
From what I understand, Big O looks at the worst case scenario. My thoughts were that if n = 2
then it would result in O(n2) however all other cases result on O(n) which is what is really confusing me.
Could someone please explain why this is O(n2) or O(n)?