SUNY Geneseo Department of Computer Science
{Date}
CSci 141, Fall 2004
Prof. Doug Baldwin
Turn in Lab 1 solutions
New Friday office hours: 2:30 - 4:00, not 1:30 - 3:00
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?
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
Resource analysis example:
// In some subclass of Robot:
drawLine( int n, Color c ) {
for ( i = 0; i < n; i++ ) {
this.paint( c )
this.move()
}
}
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()
}
}
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).