{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cps6-111110Handout

cps6-111110Handout - • Rules – Base case(way out – no...

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

View Full Document Right Arrow Icon
CompSci 6 Introduction to Computer Science November 11, 2011 Prof. Rodger Lect by Jannie Tan Announcements For next time, work old test questions No Reading Quiz Apt-05 due Tuesday – One apt MedalTable – use a dictionary Recursion Method calls a clone of itself Solves a problem by solving smaller subproblems “looping” by recursive calls – CAUTION – don’t add a loop, it is implicit CompSci 100e, Spring2011 3 Examples: recursionMisc.py Calculates and prints the sum of integers from a list that are even Print the numbers one per line Mystery recursion CompSci 100e, Spring2011 4
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
Recursion (more) Watch out for infinite recursion – No way out, what happens? – Segmentation fault, out of memory
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • Rules – Base case (way out) – no recursive call – Recursive call(s) – solve a smaller problem CompSci 100e, Spring2011 5 Recursion vs Iteration Which method do you use? • Iteration – Easier to define – Faster – recursion takes some overhead • Recursion – Easier to define – Shorter code CompSci 100e, Spring2011 6 Types of Recursion • Tail recursion – One recursive call at the end of a method – Easy to replace with a loop • Reverse something – One recursive call “before”process • Multiple Recursion – More than one recursive call CompSci 100e, Spring2011 7 Other Examples of Recursion • randomSentences.py • FileVisit.py...
View Full 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