Open In App

Algorithms | Analysis of Algorithms | Question 14

In the following C function, let n >= m. 

int gcd(n, m)
{
    if (n % m == 0)
        return m;
    n = n % m;
    return gcd(m, n);
}

                    

How many recursive calls are made by this function?
(A) (log(n))
(B) (n)
(C) (log(log(n)))
(D) (sqrt(n))



(A)

A

(B)

B



(C)

C

(D)

D


Answer:(A)
Explanation:

Above code is implementation of the Euclidean algorithm for finding Greatest Common Divisor (GCD).


Quiz of this Question
Please comment below if you find anything wrong in the above post
Article Tags :