This preview shows pages 1–5. Sign up to view the full content.
Recursion
1
Recursion
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Recursion
2
Top Down Problem Solving
Many problems become much more manageable to solve when
they have been broken down into smaller problems.
This
technique has a few names:
top down problem solving
divide and conquer
The problem is divided using stepwise refinement.
For certain
problems, each stepwise refinement is actually an instance of
the bigger problem using a smaller input set.
These problems have a
recursive
solution.
Recursion
3
Recursion
Any function that is implemented by calling itself is called a
recursive
function.
Consider the following crude implementation of factorial:
int factorial(int value)
{
int ret = 1;
if (value > 1)
ret =
value * factorial(value 1);
return ret;
}
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Recursion
4
When to Use Recursion
Problems having the following characteristics lend themselves to
recursion:
•
One or more simple cases of the problem have a straightforward,
nonrecursive solution called the
base case
.
•
The other cases can be redefined in terms of problems that are
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 03/17/2010 for the course CS 162 taught by Professor Fant during the Spring '08 term at Portland State.
 Spring '08
 Fant
 Recursion

Click to edit the document details