SUNY Geneseo Department of Computer Science


Introduction to Theory

{Date}

CSci 141, Fall 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Turn in Lab 1 solutions

New Friday office hours: 2:30 - 4:00, not 1:30 - 3:00

Questions?

Reading Summary

Sections 3.1, 3.2, 3.6

About algorithms and whether a method is an algorithm

How to prove a method is an algorithm

Conditions for a method to be an algorithm

Whether an algorithm is efficient

Best way to determine if algorithm is correct is proof

Execution time analyses?

Some Theoretical Analyses

This algorithm (or expression) supposedly computes the number that is fraction f of the way between numbers n1 and n2

    partOfTheWay( n1, n2, f )
        // Precondition: n1 <= n2
        return f * n2 + (1-f) * n1

[A Fraction of the Distance between n1 and n2]

Resource analysis example:

    // In some subclass of Robot:
    drawLine( int n, Color c ) {
        for ( i = 0; i < n; i++ ) {
            this.paint( c )
            this.move()
        }
    }

[A Robot that Has Painted 3 Tiles Red]

Here's an algorithm that supposedly makes a robot paint the border of its room (i.e., the tiles adjacent to the walls):

    // In some subclass of Robot:
    paintBorder( Color c ) {
        // Preconditions: There are no
        // obstructions other than the walls in the
        // room
        while ( this.okToMove() ) {
            this.move()
        }
        // robot is at wall
        this.paintSide( c )
        this.paintSide( c )
        this.paintSide( c )
        this.paintSide( c )
        this.paintSide( c )
    }
    paintSide( Color c ) {
        this.turnLeft()
        while ( this.okToMove() ) {
            this.paint( c )
            this.move()
        }
    }

[The Border of a Room Painted Blue]

Next

Experimentation (the scientific method) in CS

Read Sections 4.1 - 4.7

Mini-assignment: Design an experiment to test the ideas above about the execution time of the draw-a-line algorithm (i.e., that time is proportional to n).


Next Lecture