Outline for May 15, 2014
Reading
:
text
, §18
Due
: Homework #3, due May 21, 2014
Work through the homework assignment
Recursion
Nested lists: is an item in a list? [
isinlist.py
]
Palindromes [
palindrome.py
]
Thinking recursively [
recfun.py
]
First: think of the recursive case (write the problem in terms of something involving a smaller instance of the problem)
Next: think of base case (when to stop)
Example: Find the length of a string
Example: Does the string only have alphabetic characters in it?
Example: Find the maximum element of a list
Example: Construct a string from a list of strings
Example: Reverse a string
Searching a list
Example use: linear search [
linsearch.py
]
Example use: recursive linear search [
rlinsearch.py
]
Speed: compare iterative and recursive Fibonacci programs [
timefibs.py
]
You can also obtain a PDF version of this.
Version of May 14, 2014 at 11:48PM