Can anyone help/explain me with this C program recursive function. These 2 function are recursive functions. They both compute (an).
1) Do they have any differences? e.g which is better and why and so on? what they other does compared to another.
2) what are the limitations for this 2 functions?
Function 1:
int f1 (int a, int n)
{
if (n == 1)
return a;
m = n/2;
return f1(a, m) * f1(a, n-m);
}
Function 2:
int f2 (int b, int x)
{
if (x == 1)
return b;
y = x/2;
temp = f2(b, y);
temp *= temp;
if (x%2 == 0)
return temp;
else
return temp*b;
}
1) Do they have any differences? e.g which is better and why and so on? what they other does compared to another.
2) what are the limitations for this 2 functions?
Function 1:
int f1 (int a, int n)
{
if (n == 1)
return a;
m = n/2;
return f1(a, m) * f1(a, n-m);
}
Function 2:
int f2 (int b, int x)
{
if (x == 1)
return b;
y = x/2;
temp = f2(b, y);
temp *= temp;
if (x%2 == 0)
return temp;
else
return temp*b;
}