CMPT 120 Lecture : Working with Recursion
20 views2 pages
20 Oct 2011
School
Department
Course
Professor
meghan78 and 39786 others unlocked
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+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers