{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 22 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 22 Recursion
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
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 * * * * * * * * * *
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
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)! ?
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
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)
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern