In the following C function, let n>=m.
int GCD(int n, int m)
{
if(n%m==0)
return m;
n=n%m;
return GCD(m,n);
}
How many recursive calls are made by this function ?
Answer:
Number of Recursive calls:
int GCD(int n, int m)
{
if(n%m==0)
return m;
n=n%m;
return GCD(m,n);
}
How many recursive calls are made by this function ?
Answer:
Number of Recursive calls:
- 0 call if n==m || if n divisible by m
- 1 call if n & m are prime numbers
- If n=6, m=4, 1 call
- If n=5, m=3, 2 calls
- So, it depends if n>m, the recursive calls would stop when n divisible by m.