cps6-111110

Cps6-111110 - – Segmentation fault out of memory • Rules – Base case(way out – no recursive call – Recursive call(s – solve a smaller

Info iconThis preview shows pages 1–8. 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Announcements • For next time, work old test questions • No Reading Quiz • Apt-05 due Tuesday – One apt MedalTable – use a dictionary
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
Recursion (more) • Watch out for infinite recursion – No way out, what happens?
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: – Segmentation fault, out of memory • 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

This document was uploaded on 01/17/2012.

Page1 / 8

Cps6-111110 - – Segmentation fault out of memory • Rules – Base case(way out – no recursive call – Recursive call(s – solve a smaller

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online