60 likes | 221 Vues
This lecture provides an overview of algorithms, the significance of the P vs NP problem in theoretical computer science, and the practical implementation of while loops in C programming. We explore the limitations of algorithms, including the famous halting problem, and engage students with related questions. The lecture includes a detailed C code example demonstrating the use of while loops to print function values, illustrating the concept of repetitive code. It emphasizes the importance of algorithms and structured programming in solving complex problems.
E N D
Overview • Lecture T4: • What is an algorithm?Turing machine • 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.
The Main Question P = NP NP P If P NP If P = NP Kevin Wayne: all NP problems are solvable, unlike Halting problem • First level. • Second level. • third level • fourth level • Most important open problem in theoretical computer science. Also ranked #3 in mathematics (Smale).
While Loop Example #include <stdio.h> 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 • Print a table of values of function f(x) = 2 - x3. A second attempt. uses while loop
Anatomy of a While Loop x = 0.0; while (x < 2.0) { y = 2 - x*x*x; printf(“%f %f”, x, y); x = x + 0.1; } C code • Previous program repeats the same code over and over. • Repetitive code boring to write and hard to debug. • Use while loop to repeat code. x 0 y 2 - x3 print x, y x x + 0.1 x < 2.0 true false
While Loop Example #include <stdio.h> 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 • Print a table of values of function f(x) = 2 - x3. A second attempt. uses while loop