Is there someone that knows what the computational cost for this two pieces of code is?
while (n > 2)
n = sqrt(n);
while (n > 2)
n = log(n);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The second would be
O(log* n)wherelog *is the iterated logarithm.Analysing the first one yields something like this:
Consider that the first algorithm executes
ktimes (basically, the number of times we have to applysqrtuntiln <= 2).Consider this reasoning:
So the first algorithm is
O(log log n).