Lecture 2
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.
Reading assignment
- Section 1.3.
- Lecture: Recursion.
- Review C++ and Unix material from your previous courses; sections 1.4-1.5 will help with C++.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Write recursive and non-recursive codes to compute Fibonacci numbers, and later look at the solutions in the
examples/Lec2
directory of this course.- Show the states of the program stack in a recursive computation of
fib(4)
.- Let a singly linked list of
int
s be sorted in ascending order. Write a recursive function that outputs the list in descending order.- Prove, using induction, that the iterative function
power
, which we discussed in class, correctly computes the power of a number.- Questions on next lecture's material
- Solve the sample quiz.
Last modified: 30 Aug 2011