SUNY Geneseo Department of Computer Science


Recursion Review

{Date}

CSci 240, Spring 2007
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture

Misc

Problem set 3 (logic) and lab 2 (experimentation) due tomorrow

Questions?

Problem set problem 3

Recursion

Section 6.1

Examples

        boolean powerOfTwo( n )
            if n == 1
                return true
            else if n < 1 or n mod 2 != 0
                return false
            else
                return powerOfTwo( n/2 )
        print( n )
            if n > 1
                output n
                print( n-2 )
                output n-1
            else
                output n

Hand out lab 3

Next

Reasoning about recursion

Read section 7.1.1


Next Lecture