recursion 5 - Recursion Recursion 1 Top Down Problem...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Recursion 1 Recursion
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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.
Background image of page 2
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; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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, non-recursive solution called the base case . The other cases can be redefined in terms of problems that are
Background image of page 4
Image of page 5
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.

Page1 / 7

recursion 5 - Recursion Recursion 1 Top Down Problem...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online