GATE CS 2007 · Asymptotic Analysis & Recurrences

MCQ · 1 mark · Problem PROG-DIVC-0139

In the following C function, let n\(\geq\)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?
  1. A
    \(\Theta (logn)\)
  2. B
    \(\Omega (n)\)
  3. C
    \(\Theta (log logn)\)
  4. D
    \(\Theta (\sqrt{n})\)

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionOfficial GATE Answer Key: Option A.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/1242/gate2007-44

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com