csc1254lect06

csc1254lect06 - CSc 1254: Lecture # 6 Recursion September...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSc 1254: Lecture # 6 Recursion September 26, 2005 Looping: Iteration v. Recursion Writing recursive functions Pitfalls of recursion The Box Method 1 Looping Iterative constructs are looping constructs such as while and for that are count-controlled or event-controlled. On the other hand a recursive function is one that calls itself and runs until a base case is reached. A base case is a special case whose solution we already know. Recursion can seem unreal at first, but as you will see, recursion is a very real and important problem solving approach that is an alternative to iteration. Some recursive solutions are impractical and inefficient. But some complex problems can have simple and elegant recursive solutions. Now, we consider the recursive and iterative definitions of a simple function the power function. Iterative definition: x n = n producttext i =1 x = x * x * x * ... * x bracehtipupleft bracehtipdownrightbracehtipdownleft bracehtipupright n times Recursive definition: x n = braceleftbigg n = 0 , 1 else x * x n- 1 1 Lets look at an iterative and recursive solution of finding...
View Full Document

This note was uploaded on 01/17/2012 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 5

csc1254lect06 - CSc 1254: Lecture # 6 Recursion September...

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

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