Introduction to Computer Science
Lecture by lecture outline
-
We presented two algorithms for calculating the greatest common
divisor of two integers. The first of these is based directly on the
definition of the greatest common divisor, and implemented in
Example1GCD_Naive.java.
The second uses the Euclidean algorithm and is implemented in
Example2GCD_Euclidean.java.
- We proved that the Euclidean algorithm terminates on any input and
that it yields the correct result. We also explained why its runtime is
much better than that of the naive algorithm. We started going over the
Java programs implementing the two algorithms, and explained a few
basic elements of the language: variables, assignment statements, the
type int, for loops and if statements. We also discussed
the function Math.random().
- We presented the printing commands System.out.print()
and System.out.println(), talked about all integer and real
types, and gave more examples of conditional statements and loops,
including while loops and nested loops.
- We discussed infinite loops and the data types char, boolean
and String .