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

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Lecture 19. Reduction: More Undecidable problems
Case study 1: Calculate the approximation of Pi
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
Repetition Repetition Important  Do things over and over thousands of times.  Computer fast, accurate and doesn't get bored. Example  count.c.
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
CS1001 Lecture 23. Overview Incompleteness and the Halting Problem Incompleteness and the Halting Problem Methods in Artificial Intelligence Methods in.
1 Module 8 Halting Problem revisited –Universal Turing machine half-solves halting problem –A universal Turing machine is an operating system/general purpose.
H2-1 University of Washington Computer Programming I Lecture 10: Loop Development and Program Schemas © 2000 UW CSE.
CIS Computer Programming Logic
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
EPSII 59:006 Spring Remote and Local Computers CSS Itaniums (Unix) Windows XP (Dorm) texas.eng.uiowa.edu (Unix) HW1.c ???? ssh (terminal and file.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 7: One More Loop Problem, Generating “random” values, Midterm Review.
Principles of Programming - NI Simple Recursion Recursion is where a function calls itself. Concept of recursive function: A recursive function is.
Data Structures Chapter 1- Introduction Mohamed Mustaq.A.
Turing and Ordinal Logic14 th September, 2012 Turing and Ordinal Logic (Or “To Infinity and Beyond …”) James Harland School of Computer Science & IT, RMIT.
Do-while loop Syntax do statement while (loop repetition condition)
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Halting Problem Introduction to Computing Science and Programming I.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
©Brooks/Cole, 2003 Chapter 17 Theory of Computation.
©Brooks/Cole, 2003 Chapter 17 Theory of Computation.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
Chapter 6 Questions Quick Quiz
Principles of Programming - NI Simple Recursion Recursion is where a function calls itself. Concept of recursive function: A recursive function is.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Chapter.
Chapter 4 Computation Chapter 4: Computation.
Young CS 331 D&A of Algo. NP-Completeness1 NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and.
Very Hard Problems I am so not kidding about this. Please grab a handout.
Recursively Enumerable and Recursive Languages
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Chapter 12 Theory of Computation Introduction to CS 1 st Semester, 2014 Sanghyun Park.
Donghyun (David) Kim Department of Mathematics and Computer Science North Carolina Central University 1 Chapter 5 Reducibility Some slides are in courtesy.
PHY 107 – Programming For Science. Today’s Goal  How to use while & do / while loops in code  Know & explain when use of either loop preferable  Understand.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
David Evans CS200: Computer Science University of Virginia Computer Science Class 26: Halting Problem It is plain at any.
Control Structures: Examples. for-loop example Q: If a=1, b=3, and x=7, what is the value of x when the loop terminates? A: x=1 for(k=a; k
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CSC 172 P, NP, Etc.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
8.1 Determine whether the following statements are correct or not
Introduction to Computing Science and Programming I
Chapter 12: Theory of Computation
while Repetition Structure
Lecture 7: Repeating a Known Number of Times
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Lecturer CS & IT Department UOS MBDIN
Lec 7.
CSCE 411 Design and Analysis of Algorithms
CNG 140 C Programming (Lecture set 8)
How Hard Can It Be?.
Lec 6.
True or False: {image} is one-to-one function.
Computer Science Core Concepts
Week 6 CPS125.
CSE 589 Applied Algorithms Spring 1999
75 previous answer What is of 37.5? ? go to.
A Few Sample Reductions
Chapter 17 Theory of Computation.
CSCE 206 Lab Structured Programming in C
75 previous answer What is of 60? ? go to.
Looping Structures.
Presentation transcript:

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

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 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 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 = x*x*x; printf(“%4.1f %6.3f\n”, x, y); x = x + 0.1; } return 0; } table2.c uses while loop

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 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 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 = x*x*x; printf(“%4.1f %6.3f\n”, x, y); x = x + 0.1; } return 0; } table2.c uses while loop