Monday 15 July 2013

algorithm - Time Complexity of a While loop that increments from 2 to x where x^2 <= N -



algorithm - Time Complexity of a While loop that increments from 2 to x where x^2 <= N -

is time complexity of while loop increments 2 x x^2 <= n o(lg n) ? can give explanation?

here's illustration of code:

public static boolean issquare(long num) { if ((num <= 1) && (num > 0)) homecoming true; long currentnumber = 2; long currentsquare = 4; while (currentsquare <= num) { if (currentsquare == num) homecoming true; currentnumber++; currentsquare = currentnumber * currentnumber; } homecoming false; }

no, complexity o(sqrt(n)). varying number squares, , comparing square of number. or increment 1 , compare square root of number.

algorithm big-o time-complexity

No comments:

Post a Comment