Topic#10 - CS162 - Topic #10 Lecture: Recursion The Nature...

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

View Full Document Right Arrow Icon
CS162 - Topic #10 Lecture: Recursion The Nature of Recursion Tracing a Recursive Function Work through Examples of Recursion Programming Project Discuss what is expected of the User’s Manual and External Design Document
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS162 - Recursion Recursion is repetition (by self-reference) it is caused when a function calls/invokes itself. Such a process will repeat forever unless terminated by some control structure.
Background image of page 2
CS162 - Recursion So far, we have learned about control structures that allow C++ to iterate a set of statements a number of times. In addition to iteration, C++ can repeat an action by having a function call itself. This is called recursion. In some cases it is more suitable than iteration.
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS162 - Recursion While recursion is very powerful and will allow us to at times simply solve complex problems it should not be used if iteration can be used to solve the problem in a maintainable way (i.e., if it isn’t too difficult to solve using iteration) so, think about the problem. Can loops do the trick instead of recursion?
Background image of page 4
Why select iteration versus recursion? Efficiency! Every time we call a function a stack frame is pushed onto the program stack and a jump is made to the corresponding function This is done in addition to evaluating a control structure (such as the conditional expression for an if statement) to determine when to stop the recursive calls. With iteration all we need is to check the control structure
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 18

Topic#10 - CS162 - Topic #10 Lecture: Recursion The Nature...

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

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