SUNY Geneseo Department of Computer Science


Recurrence Relations for Analyzing Algorithms

{Date}

CSci 141, Fall 2003
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Hand out Lab 8

Questions?

Lab 7 - "primitive linedrawing message" = message provided by LineDrawing, e.g.,

Lab 7 due Friday

Recurrence Relations and Algorithms

Read Section 7.2.2 through factorial example (pg. 297)

How recursion works?

Recurrence relation

Implicit parameters

Examples

How many "println" messages in

Algorithm:

    countDown( n )
        if ( n > 1 )
            System.out.println( n ) <- count these
            countDown( n - 1 )

Recurrence:

Closed Form:

n P(n)

1

0
2 1+P(1) = 1 + 0 = 1
3 1+P(2) = 1 + (1 + 0) = 2

Guess n-1

Prove that P(n) = n -1 by induction on n

Next

Finish applying recurrence relations to algorithm analysis

Mini-Assignment

    manyMessages( int n )
        if ( n > 0 )
            System.out.println( "Hello world" )
            this.manyMessages( n-1 )
            this.manyMessages( n-1 )

Finish reading Section 7.2.2


Next Lecture