12-recursion

# 12-recursion - COMP 202 Recursion COMP 202 Introduction to Computing 1 CONTENTS Recursion Recursion vs Iteration Indirect recursion Runtime stacks

This preview shows pages 1–7. Sign up to view the full content.

COMP 202 – Introduction to Computing 1 COMP 202 - Recursion 1 COMP 202 Recursion CONTENTS : Recursion Recursion vs Iteration Indirect recursion Runtime stacks

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

View Full Document
COMP 202 – Introduction to Computing 1 COMP 202 - Recursion 2 Recursive Thinking A recursive definition is one which uses the word or concept being defined in the definition itself GNU Gnu's Not Unix LAME Lame Ain't an MP3 Encoder
COMP 202 – Introduction to Computing 1 COMP 202 - Recursion 3 Recursive Definitions Consider the following list of numbers: 24, 88, 40, 37 Such a list can be defined as A LIST is a: number or a: number comma LIST That is, a LIST is defined to be a single number, or a number followed by a comma followed by a LIST The concept of a LIST is used to define itself

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

View Full Document
COMP 202 – Introduction to Computing 1 COMP 202 - Recursion 4 Recursive Definitions The recursive part of the LIST definition is used several times, terminating with the non-recursive part: number comma LIST 24 , 88, 40, 37 number comma LIST 88 , 40, 37 number comma LIST 40 , 37 number 37
COMP 202 – Introduction to Computing 1 COMP 202 - Recursion 5 Infinite Recursion All recursive definitions have to have a non-recursive part If they didn't, there would be no way to terminate the recursive path Such a definition would cause infinite recursion This problem is similar to an infinite loop The non-recursive part is often called the base case

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

View Full Document
COMP 202 - Recursion 6 Recursive Definitions N!, for any positive integer N, is defined to be the product of all integers between 1 and N inclusive This definition can be expressed recursively as: 1! = 1 N! = N * (N-1)! The concept of the factorial is defined in terms of
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/29/2010 for the course COMP 202 taught by Professor Verbrugge during the Fall '07 term at McGill.

### Page1 / 21

12-recursion - COMP 202 Recursion COMP 202 Introduction to Computing 1 CONTENTS Recursion Recursion vs Iteration Indirect recursion Runtime stacks

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

View Full Document
Ask a homework question - tutors are online