Department

Electrical and Computer EngineeringCourse Code

ECE244H1Professor

Tarek AbdelrahmanChapter

14This

**preview**shows half of the first page. to view the full**2 pages of the document.** ECE244 Chapter 14 (Recursion)

What is a recursion?

- Function definition that may contains a call to the function being defined

- Every call of the function must eventually lead to a stopping case, or else the function

call will never end because of an infinite chain of recursive calls

Base case: one or more cases that function accomplishes without using any recursive calls

What is a stack?

- Specialized kind of memory structure that is analogous to a stack of paper

- Only the top object is accessible

- Last-in / first-out (LIFO) memory structure

(the last input is the first output)

- For computers to keep track of recursion

How to make sure your recursive function is correct?

For recursive function that returns a value

1. There is no infinite recursion

2. Each stopping case returns the correct value of that case

3. If all recursive calls returns the correct value, then the final value returned by the

function is the correct value

For a void function

1. There is no infinite recursion

2. Each stopping case returns the correct value of that case

3. If all recursive calls perform their actions correctly, then the entire case performs

correctly

What’s the difference between recursion and overloading?

What is a palindrome?

- Word that reads the same from left to right and from right to left

###### You're Reading a Preview

Unlock to view full version