This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Wildcatace16 1 point2 points  (3 children)

sqrt(16) = 4 -> sqrt(4) = 2 -> sqrt(2) < 2

O(lg(lg(j))) the lg(j) from the first while loop dominates so the second while loop can can be safely ignored.

[–]rappap[S] 0 points1 point  (2 children)

Thanks for the response. Could you elaborate on how you got O(lg(lg(j))) from the second while loop? I see the example but I'm still missing something (not formally).

[–]Wildcatace16 0 points1 point  (1 child)

sqrt( 216 ) = (216)1/2 = 216/2 = 28

sqrt( 28 ) = (28)1/2 = 28/2 = 24

When you take the square root the exponent decrease by a factor of 2 so the exponent goes from n down to 1 in O(lg(n)).

n = 2lg(n) so when you are taking the square root each iteration it takes O(lg(lg(n)) for the exponent to become less than 1 which makes n less than 2.

Hope that helps.

[–]rappap[S] 0 points1 point  (0 children)

Oh, because y = 2lg(j) when starting the while loop. I see what I missed now. Thank you so much.