433 views
1 votes
1 votes

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))

1 Answer

0 votes
0 votes
For gcd calculation.. The first condition of code is to check the best case which is of order O(1) the remaining code deals with worst case that is of order log(n)..  Therefore complexity will be of log(n).. For verification you can take value of m and n and then count the steps..

Related questions

4 votes
4 votes
3 answers
1
kallu singh asked Jan 20, 2018
460 views
1 votes
1 votes
1 answer
2
kallu singh asked Aug 19, 2017
242 views
What could be the best algorithm from the following when the time complexity is measured based bon the number of swaps performed by the sorting algorithm?1. Selection sor...
1 votes
1 votes
1 answer
3
1 votes
1 votes
1 answer
4
kallu singh asked Aug 13, 2017
667 views
Q. In Quick sort ,for sorting n element ,the (n/4)th smallest element is selected as pivot using an O(n) time algorithm. What is the worst case tome complexity of the Qu...