686 views
1 1 vote

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 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..
Position:
Show:

Related questions

4 4 votes
3 3 answers
949
949 views
kallu singh asked Jan 20, 2018
949 views
A certain problem is having an algorithm with the following recurrence relation.\[T(n)=2 \cdot T(\sqrt{n})+n\]How much time would the algorithm take to solve the problem?
1 1 vote
1 1 answer
532
532 views
kallu singh asked Aug 19, 2017
532 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 1 vote
1 answers 1 answer
877
877 views
iarnav asked Mar 29, 2018
877 views
*NOTE: I'm not looking to find the Time Complexity, but I'm looking for number of comparisons and the answer is3/2n -2T(n) = 2T(n/2) +2 T(2) = 1T(1) = 0and I'm stuck at t...
1 1 vote
1 1 answer
982
982 views
kallu singh asked Aug 13, 2017
982 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...