Time complexity mcq

Please explain solution.
Find the Complexity of the given code.

int gcd(int n, int m)
{
if (n%m ==0) return m;
if (n < m) swap(n, m);
while (m > 0)
{
n = n%m;
swap(n, m);
}
return n;
}

ans : Θ(logn)

and this question also : Please explain this mcq question :
lg (n!) = … ?
ans : O(n lg n)

hi poorva
for gcd()
the complexity is logn
because the n is decrease each time by m
like take example
if n is decrease by 2 u have time complexity
log base 2 (n)
here exact complexity will be
log base m(n)

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

please explain second question also
log(n!) = ?

Can u tell me the recurrence relation of that