For this algorithm, would the Time Complexity or Big O of N be O(n)
, O(log n)
or something else?
Code here:
int i = 1;
while(i*i <= n){
System.out.println(i);
i += 2;
}
For this algorithm, would the Time Complexity or Big O of N be O(n)
, O(log n)
or something else?
Code here:
int i = 1;
while(i*i <= n){
System.out.println(i);
i += 2;
}
Please look into examples provided in What does O(log n) mean exactly? and on wiki page Linear_time. There is good explanation how to count complexity. According to it your algorithm complexity would be O(n), because you have one loop, which depends on provided 'n' variable.