I am new to time complexities and asymptotic notation. I was looking at this video: https://www.youtube.com/watch?v=9TlHvipP5yA to figure out the time complexity of a piece of code shown below
The code concludes that the time complexity for the code below is O(Sqrt(n));
When I supply different n values, I am expecting Sqrt(n) # of outputs but this doesn't verify the O(Sqrt(n)) analysis. Can someone please explain why it is so?
For example if I have n = 10, I am expecting Sqrt(10) outputs which is ~ 3 outputs or 4 if you round up I guess. IS this illogical?
Thanks in advance.
p = 0;
for( int i = 0; p <= n; i++){
p = p + i;
System.out.println(p);
}