CS 136 - Lecture 1
- Why take CS 136?
- Team:
- Sample problems:
- Your responsibilities:
- Design vs. Coding from Tomassia
- Java syntax for Pascal features
- Sample Program
Learn about designing correct and efficient algorithms and data structures
- learned to crawl in CSCI 134/135 - now learn to run
How to implement algos and data structures in Java.
How to evaluate and visualize data structures and algos.
How to design large programs (in object-oriented way) so that it is easy to
modify them.
Course web page: http://www.cs.williams.edu/~kim/cs136/
- Write a backtracking algorithm to find a path from Williamstown to San
Diego.
- Find the shortest path from Williamstown to San Diego on interstate
system
(and do it efficiently)
- Schedule final exams so there are no conflicts.
- Design and implement a scientific calculator.
- Design and implement a simulator that lets you study traffic flow in
a city or airport.
- Come to lectures (if read in advance, will make more sense)
- After lectures review notes and study examples carefully until you
understand them.
- Come to labs well-prepared with good designs. Most important time.
- Don't remain confused
- Come see me during office hours when have questions on lecture
material.
- Come see me or TA's when have questions about program.
- Head off problems before they become severe.
- Follow honor code guidelines.
I can help present material to you to make it easier for you to learn.
- I cannot "teach" you.
- CS is not a spectator sport.
Data Structure and Algorithm Design goals:
- Correctness
- Efficiency
Implementation Goals:
- Robustness (produces correct output for all inputs - including
erroneous input)
- Adaptability (can evolve over time with new requirements - 2000 problem)
- Reusability (Use same code in multiple situations)
Base types: boolean, char (16 bit), int (32 bit), long (64 bit), float (32
bit), double (64 bit);
Distinguish int and long constants by adding "L" for long - e.g.
126L
Distinguish float and double constants by adding "f" or "F" for float -
e.g., 3.1415f
Strings: "This is a string", + used for concatenation: "This is "+"a
string."
Results of string + anything is string: "#"+17 is same as "#17"
Briefly review syntax of "traditional" constructs: assignment, "if", "for",
"while", declarations, ==, !=, etc.
Declarations not separated from rest of code
- type goes before variablename
- can be mixed with statements
- can be initialized in declarations
Example: int x = 17;
x := e; => x = e;
begin ... end => {...}
if => drop "then"
while => drop "do"
repeat .. until cond => do {...} while !cond;
for i := 10 to 20 do => for (int i = 10; i <= 20; i++)
begin ... end {...}
Semicolons used as line terminator, not separator.
// starts comments which go to end of line
/* multi-line comments
are done like this */
class SillyProgram{
public static void main(String[] args){
// void as return type means this is a procedure
int sum = 0;
for (int count = 1; count <= 10; count++){
sum = sum + count;
}
if (sum > 50){
System.out.println("Sum is big: "+ sum);
// + sum converts sum to string and concatenates
} else {
System.out.println("Sum is little: "+ sum);
}
}
}
We'll see later why "class", "public", "static" are used here.
Read hand-out and Chapter 3 of Core Java for more Java details.