{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture22

lecture22 - CS111 Intro to Computer Science Lecture 22...

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

CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 22 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 22 Recursion

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 22 No class Thanksgiving week No class Thanksgiving week There will be no class Monday because it is a Rutgers Wednesday There will be no class Thursday because it is Thanksgiving
CS111: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 22 Recursion Recursion Recursion is a way of looking at a problem EG problem: print pattern like * * * * * * * * * *

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 22 Recursion Recursion Non-recursive view * * * * * * * * * * A size 4 triangle is four lines, lengths 1, 2, 3, 4
CS111: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 22 Recursion Recursion Recursive view * * * * * * * * * * A size 4 triangle is A size 3 triangle, followed by A line of length 4

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 22 Recursive Definitions in Math Recursive Definitions in Math Factorial n! = n * (n-1)! 1! = 1 e.g., 3! = 3*2! = 3 * (2 * 1!) = 3 * (2 * 1) = 6 Definition looks circular, but is not Two parts: recursive case base case
CS111: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 22 Seeing recursion look at a problem as if it were “pregnant”: inside it is a small version of the same problem What is N! ? What is (n-1)! ?

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 22 Method Call Method Call What happens when a method calls itself? The same things that happen when it calls any other method: Evaluate arguments in the call Set up new invocation record with parameters Start at beginning of called procedure, go to end Continue the calling procedure, right after the call See CallExample.java
CS111: Slides for Prof. Steinberg ʼ s lecture 9 Lecture 22 Note about Note about CallByExample CallByExample Things done before recursive call are done in order (done shallow to deep) Things done after the recursive call are done in reverse order (done deep to shallow)

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

View Full Document
CS111: Slides for Prof. Steinberg ʼ s lecture 10 Lecture 22 How Do Non-Recursive calls How Do Non-Recursive calls Work?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern