Skip to content
Related Articles

Related Articles

Algorithms | Analysis of Algorithms | Question 14
  • Difficulty Level : Basic
  • Last Updated : 20 Feb, 2013

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) \theta(logn)
(B) \Omega(n)
(C) \theta(loglogn)
(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 for time complexity.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :