Lecture 17
Learning objectives
After this class, you should be able to:
- Given a recursive code, draw a figure to show how the state of the run time stack changes with time.
- Given a recursive definition of a formula or an algorithm, write code that computes the formula or implements the algorithm, and prove the correctness of your implementation.
- Given a simple recursive algorithm, derive the time complexity for executing it.
Reading assignment
- Section 5.1 - 5.8.
- Page 216 and 217.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Chapter 5, exercise 2. (If group_number % 2 = 0)
- Let a singly linked list of
int
s be sorted in ascending order. Write a recursive function that outputs the list in descending order. (If group_number % 2 = 1)
- Implement the
power
function using a stack, instead of implementing it recursively. (All groups)
- Prove, using induction, that the iterative function
power2
, which we discussed in class, correctly computes the power of a number.
- Let a function
f
be defined such that f(0) = 1. f(n) = 2*f(n/2)
. Derive the time complexity of computing this function recursively.
- Questions on next lecture's material
- Draw any tree that you wish to, such as a family tree, or the tree of an organization for which you work. What is the height of your tree? Which node is the root of the tree.
Last modified: 19 Oct 2004