Recursion
, What is recursion?
• Sometimes, the best way to solve a problem
is by solving a smaller version of the exact
same problem first
• Recursion is a technique that solves a
problem by solving a smaller problem of the
same type
, When you turn this into a program, you end
up with functions that call themselves
(recursive functions)
int f(int x)
{
int y;
if(x==0)
return 1;
else {
y = 2 * f(x-1);
return y+1;
}
}
, What is recursion?
• Sometimes, the best way to solve a problem
is by solving a smaller version of the exact
same problem first
• Recursion is a technique that solves a
problem by solving a smaller problem of the
same type
, When you turn this into a program, you end
up with functions that call themselves
(recursive functions)
int f(int x)
{
int y;
if(x==0)
return 1;
else {
y = 2 * f(x-1);
return y+1;
}
}