Tue Nov 26
Aside ...the perils of object oriented coding
in class
I've attached the programs we did in class, length.py and max.py. I also showed a towers of hanoi program.
recursion
Definition: recursion.
See "recursion".
Discussion topics :
- the basic idea : a function that calls itself, along with a stopping condition
- great for self-similar data structures : lists, graphs, ...
- recursive algorithms :
- linear search ... look at each element in turn
- binary search (if ordered) ... explicit loop vs recursive implementation
- time (i.e. number of steps) efficiency : log base 2 vs linear vs exponential
- wikipedia
Code examples :
Just for fun :
This site isn't python,
but is a nice collection of images defined with recursion.
Something along these lines could be accomplished
with Zelle's graphic library as a possible final project.
Recursion Class Exercise :
Write a recursive function that finds the maximum value of a list.
The idea is to think of a list recursively as
(list) = (first_element, list)
and so max(list) = max( first_element, max(list) )
What is the stopping condition ?