SUNY Geneseo Department of Computer Science


Induction and Algorithms, Part 2

{Date}

CSci 141, Spring 2005
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Hand out Lab 5

Questions?

The "printA" Algorithm

    printA( n )
        if n > 1
            print "AA"
            printA( n - 1 )
        else
            print "A"

Mini-assignment: finish proving that it prints 2n-1 A's

Proof by induction on n

Prove (by induction) Friday's other claim about this algorithm: that it prints an odd number of A's

Towers of Hanoi

    solve( n, source, dest, spare )
        if n > 0
            solve( n-1, source, spare, dest )
            move 1 disk from source to dest
            solve( n-1, spare, dest, source )

[Induction Reasons About Moving the Top n-1 Disks]

Prove that this really always solves an n-disk towers of Hanoi puzzle, n >= 0

Induction on number of disks, n

Next

Deriving the number of steps a recursive algorithm executes

Read Section 7.2.1


Next Lecture