This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSE 143 Lecture 12 (B) Recursion reading: 12.1  12.2 slides created by Marty Stepp http://www.cs.washington.edu/143/ 2 Recursion recursion : The definition of an operation in terms of itself. Solving a problem using recursion depends on solving smaller occurrences of the same problem. recursive programming : Writing methods that call themselves to solve problems recursively. An equally powerful substitute for iteration (loops) Particularly wellsuited to solving certain types of problems 3 Why learn recursion? "cultural experience"  A different way of thinking of problems Can solve some kinds of problems better than iteration Leads to elegant, simplistic, short code (when used well) Many programming languages ("functional" languages such as Scheme, ML, and Haskell) use recursion exclusively (no loops) A key component of the rest of our assignments in CSE 143 4 Exercise (To a student in the front row) How many students total are directly behind you in your "column" of the classroom? You have poor vision, so you can see only the people right next to you. So you can't just look back and count. But you are allowed to ask questions of the person next to you. How can we solve this problem? (recursively ) 5 The idea Recursion is all about breaking a big problem into smaller occurrences of that same problem....
View
Full
Document
 Spring '08
 SR
 Computer Science, Recursion

Click to edit the document details