Outline for February 4, 2019
Recursion
n
factorial c
nfact.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
Recursion
Palindromes [
palindrome.py
]
Fibonacci numbers [
rfib.py
]
Sum of digits [
sumdigits.py
]
Greatest common divisor [
gcd.py
]
Nested lists: is an item in a list? [
isinlist.py
]
Tower of Hanoi [
hanoi.py
]
isinstance(obj,type)
function
type
is
bool
,
float
,
int
,
list
,
str
,
tuple
Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: Version of January 30, 2019 at 8:10PM
Winter Quarter 2019
You can get a PDF version of this