Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Algorithms | Analysis of Algorithms | Question 14

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

C




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) \\theta (log(n))
(B) \\Omega (n)
(C) \\theta (log(log(n)))
(D) \\theta (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). Please see http://mathworld.wolfram.com/EuclideanAlgorithm.html for time complexity.


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

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads