I am busy with a task and I am struggling with a question. I know that I should not ask questions about the appointment directly, so I understand if I do not get direct answers. But it doesn’t matter here.
We have to calculate the runtime complexity for different algorithms, I'm stuck with this.
for(int i = 1 ; i < n ; i++)
for(int j = 0 ; j < i ; j +=2)
sum++;
Now, with my understanding, my first thought will be less than O (n 2 ), because the nested loop does not work full n times, and yet the variable j is incremented by 2 every loop, rather than iterating like a regular loop. Although, when I did some modeling of the code with N = 10, N = 100, N = 1000, etc., I got the following results when I deduced the sum variable.
N = 10 : 25,
N = 100 : 2500,
N = 1000 : 250000,
N = 10000 : 25000000
When I look at these results, O Notations seems to have much more than just O (n).
4 , : O (1), O (n 2), O (n) O (logn). , , , O (n 2), . , , .
!