SUNY Geneseo Department of Computer Science


Induction and Algorithms, Part 1

{Date}

CSci 141, Spring 2005
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Questions?

Binary digits needn't be static

A Review/Preview

Recall the bracket algorithm

    // In some subclass of Robot...
    bracket( n )
        if n > 1
            this.paint( Yellow )
            this.move()
            this.bracket( n-1 )
            this.move()
            this.paint( Yellow )
        else
            this.paint( Yellow )
            this.turnLeft()

Contrast to iterative version

Summary of how this works

[Base and Recursive Cases for Drawing Brackets]

Proofs about Recursive Algorithms

Read Section 7.1.2

Way to prove things about recursive algorithms

Use small problem to prove large problems

Base case

Induction hypothesis

Can be used for algorithms that return values

Weak vs strong induction

Example Proofs

What do you think this prints?

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

Prove it

Prove printA(n) prints 2n -1 A's

Mini-assignment: finish proof


Next Lecture