SUNY Geneseo Department of Computer Science


Introduction to Recurrence Relations

{Date}

CSci 141, Fall 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

First hour exam next Thursday (Oct. 7)

I'm out of town (most of) Wednesday through Sunday after Fall break (i.e., gone Oct. 13 through 17).

Hand out Lab 5

Questions?

Lab exercise to check if a string is a palindrome?

    if length = 0
        return ...
    else if length = 1
        return ...
    else
        compare first and last characters,
        use recursion
    return s.charAt(0) == s.charAt( s.length()-1 )
        && palindrome( s.substring(1,s.length()-1) )

Draw a Check Mark

    // In some subclass of Robot
    drawCheck( int n )
        if n = 1
            this.paint( Yellow )
            turn around
        else
            this.paint( Yellow )
            this.move()
            this.drawCheck( n-1 )
            this.move()
            this.turnRight()
            this.move()
            this.paint( Yellow )
            this.turnleft()

Prove the above correct (i.e., draws check, leaves robot facing "out" of check mark on last tile of diagonal stroke)

[Robot at End of Checkmark]

Reading Summary

Section 7.2 through "A First Example" in 7.2.2

Recurence relation is a recursive counting technique, can be used to count steps in recursive algorithm

Mathematical functions as examples

Necessities:

Closed forms: produce same values as recurrence relations

Prove closed forms using induction

Practice with Recurrences

Example

Find closed form

When n = 1, f(n) = 3 + f(0) = 3 + 7 = 10

Guess: f(n) = 3n + 7

Prove this:

Next

Recurrence relations and algorithms

Read rest of Section 7.2 (i.e., middle of page 230 through middle of page 238)


Next Lecture