Presentation is loading. Please wait.

Presentation is loading. Please wait.

Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Lecture S1: Sample Lecture.

Similar presentations


Presentation on theme: "Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Lecture S1: Sample Lecture."— Presentation transcript:

1 Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Lecture S1: Sample Lecture

2 2 Overview Lecture T4: n What is an algorithm? Turing machine n Which problems can be solved on a computer? Not the halting problem. Here’s a question for the student to fill in the answer.  Here’s the secret answer.

3 3 The Main Question First level. n Second level. – third level  fourth level Most important open problem in theoretical computer science. Also ranked #3 in mathematics (Smale). NP P If P  NP If P = NP P = NP Kevin Wayne: all NP problems are solvable, unlike Halting problem Kevin Wayne: all NP problems are solvable, unlike Halting problem

4 4 While Loop Example Print a table of values of function f(x) = 2 - x 3. A second attempt. #include int main(void) { float x, y; printf(“ x f(x)\n”); x = 0.0; while (x < 2.0) { y = 2.0 - x*x*x; printf(“%4.1f %6.3f\n”, x, y); x = x + 0.1; } return 0; } table2.c uses while loop

5 5 Anatomy of a While Loop Previous program repeats the same code over and over. n Repetitive code boring to write and hard to debug. n Use while loop to repeat code. x < 2.0 x  0 y  2 - x 3 print x, y x  x + 0.1 true false x = 0.0; while (x < 2.0) { y = 2 - x*x*x; printf(“%f %f”, x, y); x = x + 0.1; } C code

6 6 While Loop Example Print a table of values of function f(x) = 2 - x 3. A second attempt. #include int main(void) { float x, y; printf(“ x f(x)\n”); x = 0.0; while (x < 2.0) { y = 2.0 - x*x*x; printf(“%4.1f %6.3f\n”, x, y); x = x + 0.1; } return 0; } table2.c uses while loop


Download ppt "Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Lecture S1: Sample Lecture."

Similar presentations


Ads by Google