This preview has intentionally blurred sections. Sign up to view the full version.View Full 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
- Fall '09
- Recursion, Tail recursion, Control flow, Prof. Rodger Lect