SUNY Geneseo Department of Computer Science
{Date}
CSci 141, Fall 2003
Prof. Doug Baldwin
Voter registration
Lab handout will be available in labs tomorrow
Exam 1 is this Friday (Oct. 10)
Section 7.2.1
Recurrence relation is recursive definition of math function
Analysis of recurrence relations involves telling how many recursive steps it does
Proof for V(m):
Closed form = non-recursive expression that defines same function as recurrence relation
Closed forms can often be derived from recurrence
Find a closed form for
n | f(n) |
---|---|
0 | 2 |
1 | 5 + f(0) = 5 + 2 = 7 |
2 | 5 + f(1) = 5 + (5+2) = 12 |
3 | 5 + (5+5+2) = 17 |
4 | 5 + (5+5+5+2) = 22 |
Closed form: f(n) = 5n + 2 ?
Prove this guess (f(n) = 5n + 2) right by induction on n
e.g., how many robot messages (move, turns, paint, etc.) in
walk( n )
if ( n > 0 )
this.move()
this.walk( n - 1 )
else
this.turnLeft()
this.turnLeft()
f(n) is number of robot messages that "walk" sends when given parameter n
Recurrence relation
Read Section 7.2.2 through factorial example (pg. 297)
Mini-assignment: How many "println" messages in
countDown( n )
if ( n > 1 )
System.out.println( n )
countDown( n - 1 )