CMPT 120 Lecture : Working with Recursion
20 views2 pages
20 Oct 2011
School
Department
Course
Professor
![CMPT 120 Full Course Notes](https://new-docs-thumbs.oneclass.com/doc_thumbnails/list_view/2242525-class-notes-ca-sfu-cmpt-120-lecture27.jpg)
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
Is there some way to take part of the problem, solve it, and get closer to the eg. for n!, we noticed that n! And we"re almost there example: spacing out a string ie. calling spaced( word ) should return w o r d if we can space-out all but the last character ( wor becomes w o r ) we"re ie. we will space-out s[:-1] first. Step 2: use the subproblem solution to finish. For factorials, if we have (n-1)!, just multiply by n eg. to get from spaced(s[:-1]) to spaced(s), append a space and s[-1] For factorials, if we have (n-1)!, just multiply by n eg. to get from spaced(s[:-1]) to spaced(s), append a space and s[-1] eg. w o r + + d so, return spaced(s[:-1]) + + s[-1] There will be a small case (or two) where this doesn"t work. These will be handled separately with an if .
Get access
Grade+
$40 USD/m
Billed monthly
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers