Computability & Complexity. Scenario I can’t write this program because I’m too dumb.

Slides:



Advertisements
Similar presentations
Algorithm Analysis.
Advertisements

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:
Part VI NP-Hardness. Lecture 23 Whats NP? Hard Problems.
NP-Completeness.
Problems and Their Classes
Complexity Classes: P and NP
NP-Hard Nattee Niparnan.
JAYASRI JETTI CHINMAYA KRISHNA SURYADEVARA
The Big Picture Chapter 3. We want to examine a given computational problem and see how difficult it is. Then we need to compare problems Problems appear.
1 The Limits of Computation Intractable and Non-computable functions.
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
The Theory of NP-Completeness
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.
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.
Theory of Computation. Computation Computation is a general term for any type of information processing that can be represented as an algorithm precisely.
CPS Today’s topics l Computability ä Great Ideas Ch. 14 l Artificial Intelligence ä Great Ideas Ch. 15 l Reading up to this point ä Course Pack.
Computability and Modeling Computation What are some really impressive things that computers can do? –Land the space shuttle (and other aircraft) from.
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:
Cs3102: Theory of Computation Class 18: Proving Undecidability Spring 2010 University of Virginia David Evans.
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 Ethics of Computing MONT 113G, Spring 2012 Session 13 Limits of Computer Science.
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.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
Halting Problem Introduction to Computing Science and Programming I.
Compsci 100, Fall What is Computing? Informatics? l What is computer science, what is its potential?  What can we do with computers in our lives?
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
Beauty and Joy of Computing Limits of Computing Ivona Bezáková CS10: UC Berkeley, April 14, 2014 (Slides inspired by Dan Garcia’s slides.)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
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.
SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.
CS10: The Beauty and Joy of Computing Lecture #22 Limits of Computing Warning sign posted at Stern Hall. Also, Apple releases new operating.
Limits to Computation How do you analyze a new algorithm? –Put it in the form of existing algorithms that you know the analysis. –For example, given 2.
Computability Heap exercise. The class P. The class NP. Verifiers. Homework: Review RELPRIME proof. Find examples of problems in NP.
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.
Week 13 - Monday.  What did we talk about last time?  B-trees  Hamiltonian tour  Traveling Salesman Problem.
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.
Computability NP complete problems. Space complexity. Homework: [Post proposal]. Find PSPACE- Complete problems. Work on presentations.
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Chapter.
Chapter 11 Introduction to Computational Complexity Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Fundamentals of Informatics Lecture 12 The Halting Problem Bas Luttik.
Chapter 12 Theory of Computation Introduction to CS 1 st Semester, 2014 Sanghyun Park.
1 Computability Tractable, Intractable and Non-computable functions.
1 1. Which of these sequences correspond to Hamilton cycles in the graph? (a) (b) (c) (d) (e)
CS 154 Formal Languages and Computability May 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesTuring.
Introduction to Computing Science and Programming I
Chapter 12: Theory of Computation
Part VI NP-Hardness.
What is Computing? Informatics?
1.5 Intractable problems.
Ch. 11 Theory of Computation
How Hard Can It Be?.
Halting Problem.
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
What is Computer Science at Duke?
Presentation transcript:

Computability & Complexity

Scenario I can’t write this program because I’m too dumb

Better scenario I can’t write this program because it’s provably impossible

Another possible scenario I can’t write this program but neither can all these famous people

Limitations of computer science Major reasons useful calculations cannot be done:  Execution time of program is too long  problem can take years or centuries to finish  Problem is not computable  no computer program can solve the problem  We do not know how to write a program to solve the problem  problems that can conceivably be solved  includes many problems in artificial intelligence and computer vision, such as understanding language, object recognition, tracking, prediction

What problems can be solved by computers?  Equivalent to: “What decision problems can be solved?”  Decision problem  problem where the answer is always YES/NO  Arbitrary problem can always be reduced to a decision problem  There are decision problems for which algorithms do not exist  there are more different decision problems than there are different programs  if there are more decision problems than programs, then it must be the case that some decision problems cannot be solved by programs

Function evaluation  A decision problem is a question with a YES/NO answer:  Is a prime number?  Is my birthday on a Sunday next year?  Did I pass the CPS1 final exam?  Sometimes a particular answer from a set of possible solutions is required  What is the smallest prime factor of ?  On what day of the week is my birthday next year?  What grade will I get on the CPS1 final exam?  The process of answering questions where a particular answer is uniquely determined from the given information can be viewed as the evaluation of a function

Functions  A function is a correspondence between a collection of possible input values and a collection of output values such that each possible input is assigned a unique output  Example: the addition function  inputs are value pairs, outputs are values representing the sum of each input pair  output is unique, exactly one value for each input pair  Process of determining output for given input is called computing or evaluating the function  The ability to evaluate functions gives us the ability to solve problems  to solve the addition problem we must evaluate the addition function

Computable functions  Algorithms are the means by which we formally express the evaluation of a function  Can we design algorithms to evaluate all functions?  No!  Exist functions so complex that there is no well-defined step-by-step process for determining their output based on their input values  The evaluation of these functions lies beyond the capabilities of any algorithmic system  These functions are said to be noncomputable  Functions whose output values can be determined algorithmically from their input values are said to be computable  functions having an algorithm that solves them

Limitations of machines  Machines can only perform computations described by algorithms  the study of computable functions is the study of the ultimate capabilities of machines  If we can build a machine with the capabilities to evaluate the entire set of computable functions, then the machines we build are as powerful as we can make them  On the other hand …  if we discover that the solutions to a problem requires the evaluation of a noncomputable function, we know the solution to that problem lies beyond the capabilities of machines

“Does extraterrestrial life exist?”  Q: Is it possible to write a Java program to answer the following question: Does extraterrestrial life exist?  A: Yes!  The question is answered either by a program that returns “yes” or by a program that returns “no  We just don’t know which program is correct

Is a problem computable?  Suppose we create a list of all programs for evaluating computable problems  To ask whether a problem is computable is to ask if there is a program in the list to solve the problem  This is not the same as actually identifying the program in the list that solves the problem  There are many computable problems whose solutions have not yet been identified

Abstract model of computation  The first abstract model of computation was defined by Alan Turing in 1936  The Turing machine  A Turing machine is a purely theoretical device, developed well before technology was capable of providing the machines we know as “computers” today  Model to study the capabilities and limitations of computational processes and computing machinery  Provide a context in which solutions to all things computable can be expressed  Provide a standard to which the power of other computational systems can be compared

Turing machine fundamentals  A tape divided into adjacent cells  each cell is inscribed with symbol from a finite alphabet  alphabet contains blank symbol and at least one other symbol  tape is arbitrarily extendible to the left and to the right  cells that have not been written to before are assumed to be filled with the empty symbol.  A head to read & write symbols on the tape and move left & right  A finite number of states  TM must be in exactly one state at any point in computation  computation begins in start state and ceases in halt state  An action table tells TM what symbol to write, how to move the head and what its new state will be given the symbol it has just read on the tape and the state it is currently in  if there is no entry in the table for the current combination of symbol and state then the machine will halt

A Turing machine The tape is an infinite sequence of cells Each cell contains a symbol (possibly blank) R/W head moves left and right along the tape The number displayed represents its current state, which can change at it computes

Turing computable  Is this really enough to compute everything?  TM is theoretical device  infinite amount of memory  computation time is irrelevant  can represent data however we choose, provided the set of symbols is finite  All attempts to characterize computation have turned out to be equivalent  Functions that can be computed by a Turing machine are said to be Turing computable

Church-Turing Thesis Every effective computation can be carried out by a Turing machine

Turing-computable  computable  A function is computable if it can be computed by a Turing machine  or, a function is computable of a program exists that can compute it  or, a function is computable if there is an effective algorithm for evaluating the function which, given any input values for which the function is defined, produces the correct result and halts in a finite amount of time  Q: Is there anything a Turing machine cannot do?  A: Yes!

Noncomputability  A function is noncomputable if there exists no Turing machine that could compute it  or, a noncomputable function is any function that cannot be computed by any program  many more functions then there are programs  not possible to have a program for every function

A noncomputable problem  Problem: List all subroutines that input an integer and return an integer  here is one short subroutine:  and here is another:  Can make infinitely many such subroutines int sub1(int x) { return 1; } int sub2(int x) { return 2; }

Halting  Programs that run forever do not halt  programA  programs with infinite loops  Programs may halt on some inputs but not on others  programB  Programs with no loops always halt  programs composed of assignment statements, if statements and the return statement int programA( int x ) { while( x == x ) x = x; return x; } int programB( int x ) { while( x > 10 ) x = x; return x; }

Halt or not?  Will the following code eventually terminate?  What if x is 8? How about 9? while(x > 1) { if(x > 2) x = x - 2; else x = x + 2; }

Halt or not?  Will the following code eventually terminate?  What if x is 8? How about 7? How about any number > 0? while(x > 1) { if( x % 2 == 0) x = x / 2; else x = 3*x + 1; }

The halting problem  Q: Is it possible to write a Java program to answer the following question Does a given program halt on all inputs?  It would be useful if we could write a program or compiler to test if a given source program contains an infinite loop  If we had such a program, then we would never execute a program with an infinite loop  This problem is known as the halting problem start does this program halt? halt yes no

The halting problem is noncomputable  There is no single finite program that will answer the halting question for all programs No finite program can be written that will check other programs and halt in a finite time giving a solution to the halting problem start does this program halt? halt yes no

Proof by contradiction  How did Turing prove that such a program is theoretically impossible?  Proof by contradiction:  Assume there is an algorithm DoesHalt(P,I) that returns “yes” if program P halts when given input I and “no” otherwise  Show that this assumption leads to a contradictory situation  Conclude that our initial assumption – the existence of a program to tell if another program halts – must be false  Great Ideas, pages

Programs that read programs  Almost every problem related to the behavior of programs is noncomputable  programs to check for property X in the behavior of all other programs  halting, equivalence, printing, correctness  We can write programs to check almost any syntactic feature of programs  a compiler is a program that reads programs  we can measure the length of programs, number of statements, characters, arithmetic expressions Program input Program output

Computable or noncomputable? 1.Write a program that inputs a sequence of characters and returns true if it is a legal Java program 2.Write a program that inputs a sequence of characters and returns true if any permutation of these characters is a legal Java program 3.Write a program that inputs a program in any programming language and returns true if the characters can be rearranged to form a legal Java program 4.Write a program that inputs a Java program and returns true if the program computes the sum of its inputs 5.Write a program that inputs two Java programs and returns true if both programs always produce the same output

Computable or noncomputable? 1.Computable 2.Computable 3.Computable 4.Noncomputable 5.Noncomputable

Not impossible, but impractical  Towers of Hanoi  how long to move n disks?  What combination of switches turns the light on?  try all combinations, how many are there?

Program execution time  How long a program takes to perform computations on large inputs  Computable problems are basically divided into two classes  Computations that can be completed in a reasonable time period are called tractable  a computation is tractable if its running time on N inputs is logarithmic or polynomial in N  Intractable computations are those that cannot be realistically completed except for small examples  a computation is intractable if its running time on N inputs is exponential in N

Examples  Tractable problems  searching or sorting N inputs  computing the sum of positive integers  N  finding the largest element in a N  N array  counting the number of characters in a Java program  Intractable problems  computing all permutations of N inputs  Towers of Hanoi  Traveling salesperson  Bin packing  Graph coloring

Tractable or intractable? 1.Write a program that inputs a sequence of characters and returns true if it is a legal Java program  tractable 2.Write a program that inputs a sequence of characters and returns true if any permutation of these characters is a legal Java program  intractable 3.Write a program that inputs a program in any programming language and returns true if the characters can be rearranged to form a legal Java program  intractable

Traveling salesperson  A traveling salesperson must visit each of some number of cities before returning home  knows the distance between each of the cities  wants to minimize the total distance traveled while visiting all of the cities  In what order should the salesperson visit the cities? Try all paths, from every starting point -- how long does this take? {a, b, c, d, e, f, g}, {b, a, c, d, e, f, g}, … a d g f e b c

Bin packing  Pack a given set of items having different sizes into a minimum number of equal-sized bins  Example:  Pack trucks with barrels using the smallest possible number of trucks  Ideas?

Graph coloring  Color the vertices of a graph such that no edge connects two identically colored vertices using the minimum number of colors

Complexity classifications  Class P  consists of all decision problems that can be solved on a deterministic sequential machine in time polynomial in the size of the input  Class NP  non-deterministic, polynomial time  consists of all decision problems whose positive solutions can be verified in polynomial time, or  solution can be found in polynomial time on a non- deterministic machine  Biggest open question in computer science: Is P = NP?

Are hard problems easy?  Easy problems are in P, hard problems are in NP  P = NP? Rich or famous?  If the answer is yes, the whole class of hard problems can be solved efficiently  TSP and bin packing are “equally hard”  one problem is reducible to the other  If no, none of the hard problems can be solved efficiently  Widely conjectured that the answer is no  P versus NP: CMI Millennium Prize Problem  first person to solve will be awarded $1,000,000 