1 Theory: Models of Computation  Readings:  Chapter 11 & Chapter 3.6 of [SG]  Content:  What is a Model  Model of Computation  Model of a Computing.

Slides:



Advertisements
Similar presentations
Turing Machines January 2003 Part 2:. 2 TM Recap We have seen how an abstract TM can be built to implement any computable algorithm TM has components:
Advertisements

Chapter 11: Models of Computation
NP-Completeness.
Complexity Classes: P and NP
CS 345: Chapter 9 Algorithmic Universality and Its Robustness
Programming Languages Wrap-up. Your Toolkit Object-oriented Imperative Functional Logic.
Computability & Complexity. Scenario I can’t write this program because I’m too dumb.
Great Theoretical Ideas in Computer Science for Some.
CSE373: Data Structures & Algorithms Lecture 24: The P vs. NP question, NP-Completeness Nicki Dell Spring 2014 CSE 373 Algorithms and Data Structures 1.
Complexity 7-1 Complexity Andrei Bulatov Complexity of Problems.
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
Complexity ©D.Moshkovitz 1 Turing Machines. Complexity ©D.Moshkovitz 2 Motivation Our main goal in this course is to analyze problems and categorize them.
Complexity 5-1 Complexity Andrei Bulatov Complexity of Problems.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
1 dKS, Spring Some practical information Lecturers: Kristoffer Arnsfelt Hansen and Peter Bro Miltersen. Homepage:
The Theory of NP-Completeness
CHAPTER 4 Decidability Contents Decidable Languages
Analysis of Algorithms CS 477/677
Chapter 11: Limitations of Algorithmic Power
CS10 The Beauty and Joy of Computing Lecture #23 : Limits of Computing Thanks to the success of the Kinect, researchers all over the world believe.
1 Introduction to Computability Theory Lecture11: The Halting Problem Prof. Amos Israeli.
Halting Problem. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have a tool that would warn us.
Complexity Theory: The P vs NP question Lecture 28 (Dec 4, 2007)
1.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
More Theory of Computing
T URING M ACHINE Dr. Manish Kumar Bajpai IIITDM Jabalpur 1.
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
Machines with Memory Chapter 3 (Part B). Turing Machines  Introduced by Alan Turing in 1936 in his famous paper “On Computable Numbers with an Application.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
Theory of Computing Lecture 15 MAS 714 Hartmut Klauck.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
CSC 413/513: Intro to Algorithms NP Completeness.
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
Halting Problem Introduction to Computing Science and Programming I.
1 Theory: Models of Computation  Readings:  Chapter 11 & Chapter 3.6 of [SG]  Content:  What is a Model  Model of Computation  Model of a Computing.
Beauty and Joy of Computing Limits of Computing Ivona Bezáková CS10: UC Berkeley, April 14, 2014 (Slides inspired by Dan Garcia’s slides.)
Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations.
CS10: The Beauty and Joy of Computing Lecture #22 Limits of Computing Warning sign posted at Stern Hall. Also, Apple releases new operating.
Complexity & Computability. Limitations of computer science  Major reasons useful calculations cannot be done:  execution time of program is too long.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
The Beauty and Joy of Computing Lecture #23 Limits of Computing Researchers at Facebook and the University of Milan found that the avg # of “friends” separating.
Fundamentals of Informatics Lecture 13 Reduction Bas Luttik.
Donghyun (David) Kim Department of Mathematics and Computer Science North Carolina Central University 1 Chapter 7 Time Complexity Some slides are in courtesy.
Capabilities of computing systems Numeric and symbolic Computations A look at Computability theory Turing Machines.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Chapter.
NP-Completeness  For convenience, the theory of NP - Completeness is designed for decision problems (i.e. whose solution is either yes or no).  Abstractly,
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Fundamentals of Informatics Lecture 12 The Halting Problem Bas Luttik.
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.
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
1 Introduction to Turing Machines
Chapter 12 Theory of Computation Introduction to CS 1 st Semester, 2014 Sanghyun Park.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesTuring.
For last lecture… Covered (for FUN and knowledge)
The Acceptance Problem for TMs
Chapter 12: Theory of Computation
Unsolvable Problems December 4, 2017.
Chapter 9 TURING MACHINES.
CSCE 411 Design and Analysis of Algorithms
Halting Problem.
Chapter 11 Limitations of Algorithm Power
Theory of Computation Lecture 23: Turing Machines III
Presentation transcript:

1 Theory: Models of Computation  Readings:  Chapter 11 & Chapter 3.6 of [SG]  Content:  What is a Model  Model of Computation  Model of a Computing Agent  Model of an Algorithm  TM Program Examples  Computability (Church-Turing Thesis)  Computational Complexity of Problems

2 Theory: Goals  To give a model of computation  to be able to reason about the capabilities of computers  To study the properties of computation  rather than being lost in the details of the machine hw/sw  To study  what computers may be able to do, and  what they cannot do  To study  What can be done quickly, and  what cannot be done quickly

3 Self Readings:  Section 11.1 –  Introduction, Models, Computing Agents

4 Theory: Models of Computation  Content:  What is a Model  Model of Computation  Model of a Computing Agent  Model of an Algorithm  TM Program Examples  Computability (Church-Turing Thesis)  Computational Complexity of Problems

5 Theory: Goals  We will construct a model of computation.  A simple, functional description of a computer  to capture essence of computation  suppress details  easy to study and reason about  Turing Machine   Turing Machine   (there are several other models)

6 Turing Machine (a picture!) Infinite Tape (with tape symbols) … 000$11b … b M Alphabet = {0,1,b,$} Machine with Finite number of States Tape Head (to read, then write) (move Left/Right)

7 Turing Machine (what is it?) “The Hardware” consists of…  An infinite tape consisting of cells  on which letters may be written  Letters comes from a fixed FINITE alphabet  A tape head which can  Read one cell at a time  write to one cell at a time.  Move left/right by one cell  A FINITE set of states.  At any given time, machine is in one of the states

8 Turing Machine (how it works!) A Turing Machine Instruction:  (Q1, s1, s2, Q2, D)  If (current state is Q1) and (reading symbol s1) then  Write symbol s2 onto the tape,  go into new state Q2,  moves one step in direction D (left or right)  Very Simple machine…  But, as powerful (computation wise) as any computer  Remark: This is the software…

9 Example: Bit Inverter   Problem: Bit Inverter   Input: A string of 0’s and 1’s   Output: The “inverted” string   0 changed to 1   1 changed to 0   Examples:       01001

10 Figure 11.4 TM Program: (S1,0,1,S1,R) // change 0 to 1 (S1,1,0,S1,R) // change 1 to 0 Bit Inverter Machine (State Diagram)

11 Figure 11.4 State 2 $ / $ / L TM Program: (S1,0,1,S1,R) // change 0 to 1 (S1,1,0,S1,R) // change 1 to 0 (S1,$,$,S2,L) // end-state (2) Bit Inverter Machine (State Diagram)

12 TM (Bit Inverter program) … 000$11b … b S1 TM Program: (S1,0,1,S1,R)  (S1,1,0,S1,R) Input = 00101$

13 TM (Bit Inverter program) - 2 … 100$11b … b S1 TM Program: (S1,0,1,S1,R)  (S1,1,0,S1,R)

14 TM (Bit Inverter program) - 3 … 110$11b … b S1 TM Program: (S1,0,1,S1,R) (S1,1,0,S1,R) 

15 TM (Bit Inverter program) - 4 … 110$01b … b S1 TM Program: (S1,0,1,S1,R)  (S1,1,0,S1,R)

16 TM (Bit Inverter program) - 5 … 111$01b … b S1 TM Program: (S1,0,1,S1,R) (S1,1,0,S1,R) 

17 TM (Bit Inverter program) - 6 … 111$00b … b S1 TM Program: (S1,0,1,S1,R) (S1,1,0,S1,R) (S1,$,$,S2,L) 

18 TM (Bit Inverter program) - 7 … 111$00b … b S2 TM Program: (S1,0,1,S1,R) (S1,1,0,S1,R) (S1,$,$,S2,L) No more Moves!!

19 Odd Parity Bit   Problem: Parity Bit   an extra bit appended to end of string   to ensure the “expanded” string has an odd number of 1’s   Used for detection of error (eg: transmission)   Examples:      

20 Figure 11.5 TM Program: 1.(S1,0,0,S1,R) 2.(S1,1,1,S2,R) 3.(S2,0,0,S2,R) 4.(S2,1,1,S1,R) 5.(S1,b,1,S3,R) 6.(S2,b,0,S3,R) Odd Parity Bit Machine (State Diagram)

21 Another Problem (in diff. notations)  Suppose initially on the tape we have $11111 B BBBBBBBBBB……. $11111 B BBBBBBBBBB…….  We want the TM to  convert first set of 1s to 0’s and  convert second set of 1’s to 2’s and  then return to the initial left most cell ($).  Note: Alphabet = {0,1,2,B,$} and Initially at leftmost cell Alphabet = {0,1,2,B,$} and Initially at leftmost cell

22 Example (Algorithm) Step 1: Initially it reads $, and moves the head right, and goes to Step 2. and moves the head right, and goes to Step 2. Step 2: If the symbol being read is 1, then write a 0, move the head right, and Repeat Step 2. then write a 0, move the head right, and Repeat Step 2. If the symbol being read is B, then move right, and go to Step 3. then move right, and go to Step 3. Step 3: If the symbol begin read is 1, then write a 2, move the head right, and repeat Step 3. then write a 2, move the head right, and repeat Step 3. If the symbol being read is B, then go to Step 4. Step 4: If the symbol being read is 0, 1, 2 or B, then move left. If the symbol being read is $, then stop. $11111 B BBBBBBBBBB

23 Example (TM Program)  Alphabet = {$,0,1,2,B}  States = {Q1, Q2, Q3, Q4}  Q1 is the starting state  Transition Table: TMState Symbol Read $B012 Q1 $,R,Q2 Q2 B,R,Q30,R,Q2 Q3 B,L,Q42,R,Q3 Q4 STOPB,L,Q40,L,Q41,L,Q42,L,Q4 HW: Translate this transition table into a TM program using notations of [SG]

24 Church-Turing Thesis  NOT a Theorem, but a thesis.  A statement that has to be supported by evidence.  Issue: Definition of computing device not clear.  Mathematically:  There is a (Partial) Functions which take strings to strings If there exists an algorithm to do a symbol manipulation task, then there exists a Turing machine to do that task.

25 Church-Turing Thesis (cont)  Two parts to writing a Turing machine for a symbol manipulation task  Encoding symbolic information as strings of 0s and 1s (eg: numbers, sound, pictures, etc)  Writing the Turing machine instructions to produce the encoded form of the output

26 Figure 11.9 Emulating an Algorithm by a Turing Machine

27 Limits of Computabiltiy:  Based on Church-Turing thesis, TM defines limits of computability  TM = ultimate model of computing agent  TM program = ultimate model of algorithm  Are all problems solvable using a TM?  Uncomputable or unsolvable problems problem for which we can prove that no TM exists that will solve it. problem for which we can prove that no TM exists that will solve it.

Solvable Problems  Bit Inversion  Computing the Parity Bit  Division by 4 (or 8 or 16…)  Sorting n numbers,  Finding the sum of n numbers,  Pattern Matching  Finding subset with largest sum,  etc., etc 28

29 Computability Q: Can we solve every problem? In Mathematics:  Godel’s Theorem: Not every true theorem about natural numbers can be proven. In Computer Science:  Not every problem can be solved.  Example: Halting Problem

30 Computability: The Halting Problem  Halting Problem: Given any program P, and any input x: Does program P stop when run on input x? Does program P stop when run on input x?  Result: Halting Problem is not computable. Namely, there is no algorithm SOLVE(P,x) such that for all P and x, we can answer Namely, there is no algorithm SOLVE(P,x) such that for all P and x, we can answer SOLVE P x Yes / No

31 Informal Proof (by contradiction)  Rough Overview of the Proof:  First, assume there is such a program Solve(P,x)  Then, “thru a sequence of logical steps” prove that we obtain a contradiction.  This implies that the original assumption must be false; (i.e., Solve(P,x) does not exist) SOLVE P x Yes / No

32 First, Assume program Solve(P,x) exist  Fact 1: Suppose “P running on x” does not halt;  Then in Step 1 Solve(P,x) outputs NO, then in Step 2, SuperSolve(P,x) halts;  Fact 2: Suppose “P running on x” halts;  Then in Step 1, Solve(P,x) outputs YES, then in Step 3,5 SuperSolve(P,x) runs into infinite loop (does not halt); SuperSolve(P,x); begin 1. If SOLVE(P,x) outputs NO 2. then stop 3. else goto step 5 4. endif 5. goto step 5. // infinite loop!! End

33 Fact 1: If “P running on x” does not halt; Fact 1: If “P running on x” does not halt; Then in Step 1, Solve(P,x) outputs NO, Then in Step 1, Solve(P,x) outputs NO, then in Step 2, SuperSolve(P,x) halts; then in Step 2, SuperSolve(P,x) halts; Fact 2: If “P running on x” halts Then in Step 1, Solve(P,x) output s YES, then in Step 3,5 SuperSolve(P,x) runs into infinite loop (Step 5) (does not halt); Fact 2: If “P running on x” halts Then in Step 1, Solve(P,x) output s YES, then in Step 3,5 SuperSolve(P,x) runs into infinite loop (Step 5) (does not halt); Now, to derive the contradiction….  Fact 1 and Fact 2 are true for all programs P and all x;  So, what if we set P = SuperSolve?  Then Fact 1 and Fact 2 becomes…

34 Now, to derive the contradiction….  Fact 1 and Fact 2 are true for all programs P and all x;  So, what if we set P = SuperSolve?  Then Fact 1 and Fact 2 becomes… Fact 1: If “SuperSolve running on x” does not halt; Fact 1: If “SuperSolve running on x” does not halt; Then in Step 1, Solve(SuperSolve,x) outputs NO, Then in Step 1, Solve(SuperSolve,x) outputs NO, then in Step 2, SuperSolve(SuperSolve,x) halts; then in Step 2, SuperSolve(SuperSolve,x) halts; Fact 2: If “SuperSolve running on x” halts Then in Step 1, Solve(SuperSolve,x) output s YES, then in Step 3,5 SuperSolve(SuperSolve,x) runs into infinite loop (Step 5) (does not halt); Fact 2: If “SuperSolve running on x” halts Then in Step 1, Solve(SuperSolve,x) output s YES, then in Step 3,5 SuperSolve(SuperSolve,x) runs into infinite loop (Step 5) (does not halt);  CONTRADICTION in both case!!

35 The Halting Problem: Some Remarks  The general Halting Problem is unsolvable;  But, it does not mean apply to a specific program  Example: Consider this program. Does it halt?  1. k  1; 2. while (k >0) do 3. print (“I love UIT2201, thank you.”); 4. endwhile; 5. print (“Everyone in UIT2201 goes to Paris”);

36 Unsolvable Problems (continued)  There are many other unsolvable problems  No program can be written to decide whether any given program always stops eventually, no matter what the input  No program can be written to decide whether any two programs are equivalent (will produce the same output for all inputs)  No program can be written to decide whether any given program run on any given input will ever produce some specified output

37 Computational Complexity of Solvable Problems  Now, turn attention to solvable problems…  Suppose problem can be solved by the computer.  Question: How much time does it take?  Problem: Searching for a Number x Algorithms: Linear Search  (n), Binary Search  (lg n)  Order of Growth: (and the  -notation)  Complexity “order” is more important than constant factors  eg: 1000 lg n vs 0.5 n (this is just  (lg n) vs  (n) )  eg: 1000n vs 0.001n 2 (or  (n) vs  (n 2 ) )

Recall this table?  From the textbook [SG3] 38

39 Order of Growth of Running Time  In tutorial, we extended the table:  Different sample algorithms,  With different time complexities.

40 Order of Growth of Running Time  Rate of growth of the running time  On a slow computer (speed = 10,000 ops / second)  Note difference between  Polynomial time complexity (n, n lg n, n 2 ) and  Exponential time complexity ( 2 n )

41 Order of Growth of Running Time  Rate of growth of the running time  On a fast computer (speed = 10 9 ops / second)  Note difference between  Polynomial time complexity (n, n lg n, n 2 ) and  Exponential time complexity ( 2 n )

42 Fast and Slow Algorithms  Some Algorithms are fast  Binary search --  (lg n) time  Finding maximum, minimum, counting, summing --  (n) time  Selection sort –  (n 2 ) time  Multiply two nxn matrix –  (n 3 ) time  Some algorithms are Slow  Printing all subsets of n-numbers (  (2 n ))  It may not be of much practical use  So, What is feasible?

43 Time Complexity of Algorithms  Algorithm is efficient if its time complexity a polynomial function of the input size  Example: O(n), O(n 2 ), O(n 3 ), O (lg n), O(n lg n), O(n 5 )  Algorithm is inefficient if its time complexity is an exponential function of the input size  Example: O(2 n ), O(n 2 n ), O(3 n )  These algorithms are infeasible for big n.

44 Complexity of Problems  Given a problem, can we find an efficient algorithm to solve it?  Yes for some problems:  Finding the maximum of n numbers, Θ(n)  Finding the sum of n numbers, Θ(n)  Sorting n numbers, Θ(n 2 ), faster ones Θ(n lg n)  computing the Hamming distance, Θ(n)  P : Class of problems that can be solved in polynomial time. (Also called easy problems)

45 Remarks:  The class P is invariant  under different types of machines  Turing machines, Pentium5, the world’s fastest supercomputer  Namely, if you can solve a problem B in polynomial time on a TM, then, then you can also solve B in polynomial time on supercomputer (and vice-versa)

46 Exponential Complexity Problems or Hard Problems  Some problems are inherently exponential time.  List all possible n-bit binary numbers; Θ(n 2 n )  List at 2 n subsets of n objects; Θ(n 2 n )  List all the n! permutations of {1,2,…,n}  These are “hard problems” that require exponential time to solve.

47 The Complexity class NP  Given a problem, instead of finding a solution, can verify a solution to the problem quickly?  Is it easier to verify a solution (as opposed to finding a solution)  NP – the class of problems that can be verified in polynomial time

48 Sample Problems in NP  There are many problem in NP  (easy to verify, apparently hard to find solution)  Examples:  Min-Difference Subsets  BinPack: packing small items into standard sized bins  TSP: Travelling Salesman Tour

Min-Diff subsets (from T9)  Given a set S = { 4, 2, 6, 8, 17, 5 },  How to divide into two subsets A and B so that the sum of A and B are as equal as possible (or the difference in the sum of A and B is as small as possible).  Example:  A = {4, 8, 6}, B = {2, 17, 5} Diff = 6  A = {2, 5, 8, 6}, B = {17, 4} Diff = 0 49

Min-Diff subsets: (Y/N answer)  Given a set S = { 4, 2, 6, 8, 17, 5 }, and K.  Can we divide into two subsets A and B so that difference in the sum is ≤ K.  Example: If we are given that K=3, it is easy to verify..  A = {4, 8, 6}, B = {2, 17, 5} Diff = 6 > K  A = {2, 5, 8, 6}, B = {17, 4} Diff = 0 ≤ K.  So, Min-Diff subsets is in class NP 50

Bin Packing Problem  See separate ppt file. 51

52  Given:  N cities (SG, NY, London, Tokyo, Sydney, etc)  Cost of travel between each pair of cities  To Find: TSP tour of all the cities  SG, to NY, London, Tokyo, … and come back to SG.  Each city visited exactly once (except first and last city is both Spore)  Aim (Opt): To minimize the cost.  Aim2: Find TSP tour of cost less than X. Traveling Salesman Problem (TSP)

TSP (status) To Date:  Many experts have tried.  Many heuristic algorithms proposed  But, no fast (polynomial time) algorithm that solves all instances of the TSP.  See examples here:

54 Traveling Salesman Problem (2)  TSP: Apparently difficult to solve.  No polynomial time algorithm known.  However, easy to verify (if cost ≤ X)  if you are given a test tour,  Can verify solution in polynomial time!!  Summary of TSP:  Easy to verify solution. (in the class NP)  Difficult to solve (find optimal solution).

55 Hardest Problems in NP  The notion of the “Hardest” Problem in NP,  Among all the many problems in NP, some are the Hardest  If the hardest problem can be solved efficiently, then ALL the problems in NP can be solved efficiently.  In 1970, Stephen Cook proved that SAT is a Hardest Problem in NP.  Then, it was shown that TSP, Bin-Packing, and Min-Diff Subsets are also all Hardest Problems Much of cryptography is based on these “hard” problems.

Biggest OPEN Problem  Is P = NP ?  The famous “P vs NP” problem.  One of the Millennium Prize Problems  US$1,000,000 for the first correct solution  

57 Summary  Models are an important way of studying physical and social phenomena  Church-Turing thesis: If there exists an algorithm to do a symbol manipulation task, then there exists a Turing machine to do that task  The Turing machine can be accepted as an ultimate model of a computing agent

58 Summary (continued)  A Turing machine program can be accepted as an ultimate model of an algorithm  Turing machines define the limits of computability  An uncomputable or unsolvable problem: We can prove that no Turing machine exists to solve the problem

59 The End…

60

61