Polycopié d'informatique Fondamentale IMA4-SC

Size: px
Start display at page:

Download "Polycopié d'informatique Fondamentale IMA4-SC"

Transcription

1 Polycopié d'informatique Fondamentale IMA4-SC Version 2013 Polytech'Lille, Villeneuve d'ascq Laure Gonnord

2 A man provided with paper, pencil, and rubber, and subject to strict discipline, is in eect a universal machine. Alan Turing, Intelligent Machinery : A Report by A. M. Turing (Summer 1948) An d'améliorer ce poly n'hésitez pas à me soumettre toute critique, suggestion, remarque ou correction, dans mon casier ou, électroniquement, à l'adresse Laure.Gonnord@polytech-lille.fr

3 Laure Gonnord Polycopié d'informatique Fondamentale IMA4SC S Table des matières 1 Introduction, automates nis et langages réguliers 4 2 Automates à pile et grammaires hors contexte 15 3 Automates à compteurs et machines de turing 22 4 Graphes, notions de NP-complétude 31 5 Construction d'un compilateur en Java 48 3/58

4 Laure Gonnord Polycopié d'informatique Fondamentale IMA4SC S Chapitre 1 Introduction, automates nis et langages réguliers Dans ce cours nous abordons le modèle de calcul le plus simple, les automates nis, ainsi que la notion de langage régulier. 4/58

5 Course introduction and schedule Informatique Fondamentale IMA S8 Cours 1 - Intro + schedule + finite state machines Until now Laure Gonnord Laure.Gonnord@polytech-lille.fr Université Lille 1 - Polytech Lille 2013 During S5,S6,S7, IMA students have learnt : (programming stuff) C programing and compiling, (conception stuff) algorithm design and encoding, (microelec) circuits and embedded systems hardware, (auto) design flows of industrial processes Solved (computation) problems by ad-hoc solutions. Until now 2/2 Course introduction and schedule Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 2 / 38 Schedule Course introduction and schedule But : No general scheme to design algorithms. (manual) evaluation of the cost of our programs. worse no assurance of correctness. even worse it there always a solution? All these problems will be addressed in this course Finite state machines (regular automata), regular languages. Notion of non determinism. Link with circuits. I/O automata, stack automata and grammars. Link to simple languages. Counter automata, Turing machines and undecidable problems. Link to classical programs. Graphs and classical problems/algorithms on graphs. Compiler Construction. (+ lab) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 3 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 4 / 38

6 Course introduction and schedule Finite state machines 1 Finite state machines 2 Regular Languages I - Regular languages and automata 3 The notion of non determinism 4 Classical Algorithms 5 Expressivity of regular languages 6 Link to other models Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 5 / 38 What for? Finite state machines Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 6 / 38 Example Finite state machines Opening/Closing door - Source Wikipedia. We want to model : the behaviour of systems with behavioural modes. the behaviour of (Boolean) circuits. sets of words. A finite representation. state transition close_door transition condition 1 Opened E: open door open_door 2 Closed entry action E: close door Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 7 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 8 / 38

7 General definition Finite state machines Finite state machine (FSM) or regular automata States are labeled, and there are finitely many (s Q) Initial state(s) (i I) and accepting (terminating/finishing) states (t F ) Transitions are finitely many. Transitions are labeled with letters (a A). The transition function is δ : Q A Q. b Finite state machines Accepted language 1/2 Accepted word A word w on the alphabet A is accepted by the automaton iff there exists a finite path from an initial state to an accepting state which is labeled by w. b s a 0 s a 1 s 2 s a 0 s a 1 s 2 w = aa is accepted/recognised. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 9 / 38 Finite state machines Accepted language 2/2 Accepted language The accepted language of a given automaton A is the set of all accepted words and is denoted by L(A). Remark : it can be infinite. L(A) = {ab k a, k N}. b s a 0 s a 1 s 2 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 10 / 38 Finite state machines Data Structure for implementation Problem : how to encode an automata? b s a 0 s a 1 s 2 The transition function can be (for instance) encoded as a transition table : s 0 s 1 s 2 s 0 a s 1 b a s 2 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 11 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 12 / 38

8 Regular Languages Regular Languages Goal 1 Finite state machines 2 Regular Languages 3 The notion of non determinism 4 Classical Algorithms Problem : how to describe languages easily in a textual linear way? use regular expressions. 5 Expressivity of regular languages 6 Link to other models Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 13 / 38 Regular expressions Regular Languages Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 14 / 38 Regular Languages Regular expression vs word Regular expression (recursive def) A regular expression e on the alphabet A is defined by induction. It can be of any of the following kinds : the empty word ε a letter a A a choice between an expression e 1 and another expression e 2 : e 1 + e 2 two successive expressions : e 1 e 2 0,1 or more successive occurrences of e 1 : e 1. A regular expression encodes the form of a word. For instance : i m a ( ) (on the alphabet {i, m, a, 3, 4, 5}) describes all words beginning by the prefix ima and finishing by one of the numbers 3, 4 or 5. A regular expression describes a language Example with A = {a, b, c, d} : e = a (b + c d) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 15 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 16 / 38

9 Regular Languages Regular Languages Regular language Linux world Regular language Given a regular expression e, L(e) denotes the set of words (the language) that are described by the regular expression e. Example with A = {0,..., 9} : e = ( ) ( ). What is L(e)? Some commands use (extended) regular expressions (regexp) : ls *.pdf lists all pdfs of the current directory grep ta*.* *.c find all lines in.c files that contains words that begin with t + some a s. sed ''s ta*.*/toto/g'' file replace all occurrences... Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 17 / 38 Regular Languages Relationship between automata and languages - 1/3 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 18 / 38 Regular Languages Relationship between automata and languages - 2/3 First, some experiments. Given the following automata A, are you able to give a regular expression e such that L(e) = L(A)? b s a 0 s a 1 s 2 And the converse : Given the following regular expression e = b (c + a), are you able to give an automaton A such that L(A) = L(e)? e =? Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 19 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 20 / 38

10 Regular Languages The notion of non determinism Relationship between automata and languages - 3/3 1 Finite state machines 2 Regular Languages General result - Kleene Theorem The regular languages are exactly the languages that are described by finite automata. What we ve done before is always possible. 3 The notion of non determinism 4 Classical Algorithms 5 Expressivity of regular languages 6 Link to other models Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 21 / 38 Goal The notion of non determinism Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 22 / 38 Definition The notion of non determinism Sometimes some info lacks to make a choice between two transitions : c q a 0 q c 1 q 2 From state q 1, there is a non deterministic choice while reading c : either go to state q 2 or stay in q 1. Non deterministic FSM A deterministic automaton is A =< A, Q, I, F, δ > with δ : A Q Q A non deterministic automata is the same with : δ : A Q P (Q) A non deterministic automata with ε-transitions is the same with δ : (A {ε}) Q P (Q) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 23 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 24 / 38

11 The notion of non determinism Classical Algorithms Example 1 Finite state machines A non deterministic automata with ε-transitions : Then L(A) = a (c d ). c p a q d r ε 2 Regular Languages 3 The notion of non determinism 4 Classical Algorithms 5 Expressivity of regular languages 6 Link to other models Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 25 / 38 Classical Algorithms Find the associated language Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 26 / 38 Classical Algorithms Construction of automaton from a regular expression Goal : Given A an automaton, find the associated language. Exercises! Goal : Given a regular expression, construct a regular automaton that recognises it. Exercises! Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 27 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 28 / 38

12 Classical Algorithms Classical Algorithms Determinisation Other Algorithms Goal : transform a non deterministic automaton into a deterministic one. Exercises! In the literature you will easily find : algorithms to eliminate ε transitions without determinising (ε closure) ; algorithms to minimise automata (the number of states) ; algorithms to use automata to find words in a text ; algorithms to test language inclusion (if they are regular)... Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 29 / 38 Expressivity of regular languages Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 30 / 38 Expressivity of regular languages Non regular languages 1 Finite state machines 2 Regular Languages 3 The notion of non determinism 4 Classical Algorithms 5 Expressivity of regular languages 6 Link to other models Important result There exists some non-regular languages. Examples of non-regular languages : {a n b n, n N}. palindromes on a non-singleton alphabet. {a p, p prime} There exists a quite systematic way to prove that a given language is not regular (Pumping Lemma). Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 31 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 32 / 38

13 1 Finite state machines Link to other models Link to other models Moore and Mealy Machines - 1 Moore : I/O machine whose output values are determined solely by the current state : 2 Regular Languages 3 The notion of non determinism 4 Classical Algorithms 5 Expressivity of regular languages 6 Link to other models source Wikipedia Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 33 / 38 Link to other models Moore and Mealy Machines - 2 Mealy : output values are determined both by the current state and the value of the input. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 34 / 38 Link to other models UML Implementation of FSMs UML variants of FSMs are hierarchical, react to messages and call functions. source Wikipedia source Wikipedia Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 35 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 36 / 38

14 Link to other models Conclusion Hardware Implementation of FSMs Summary It requires : a register to store state variables a block of combinational logic for the state transition (optional) a block of combinatorial logic for the output Regular Automata or Finite State Machines are : Acceptors for regular languages. But some languages are not regular. Algorithmically efficient. Useful to describe (simple) behaviours of systems. Closely linked to circuits. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 37 / 38 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 38 / 38

15 Laure Gonnord Polycopié d'informatique Fondamentale IMA4SC S Chapitre 2 Automates à pile et grammaires hors contexte Les automates à pile sont un modèle de calcul un peu plus puissant que les automates nis. Nous caractériserons leur pouvoir d'expressivité en terme de grammaire. 15/58

16 Informatique Fondamentale IMA S8 Cours 2 - Stack automata + Grammars Laure Gonnord Laure.Gonnord@polytech-lille.fr II - Stack automata and Grammars Université Lille 1 - Polytech Lille 2013 Stack automata Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 2 / 22 Stack automata What for? 1 Stack automata 2 Grammars Express more than regular languages! Give a way for automata to count, to have a memory. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 3 / 22 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 4 / 22

17 Stack automata Stack automata Example General definition (source : Wikipedia) Stack/P automata States (Q), initial state (q 0 ), finite states (F). Two alphabets (one for read : Σ one for stack : Γ) γ 0 Γ the end of stack character. Transitions are finitely many. A stack to write into. Transitions use the stack. The transition function is : Q (Σ ε) Γ P(Q Γ ) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 5 / 22 How it works? 1/3 Stack automata Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 6 / 22 How it works? 2/3 Stack automata Configuration A configuration is a triple (q, w, α) where : q is the current state w Σ the part of the input tape which is not yet read α Γ the current stack word Two different conditions for accepting words : accepting state : the read word leads to a configuration of the form (q, ε, α) where q F (with any α) empty stack :... (q, ε, γ 0 ) (with any q, but γ 0 is the empty stack character. Given a configuration (q, w, α), the next one is computed by the help of the transition function Q (Σ ε) Γ P(Q Σ ) : enabled transitions : those of the form (q, a, A) (q, A ) where a is the next letter to read on the input tape (or ε), and A the letter on top of the stack : w = aw and α = Aα. Pick one enabled transition, and compute the next configuration (q, w, A α ). Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 7 / 22 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 8 / 22

18 Stack automata Stack automata How it works? 3/3 Important theoretical results on PDA (source : wikipedia) Important Stack automata are non deterministic! The two acceptance criteria define the same class of languages Try to derive 0011 and 00111! The PDA recognises {0 n 1 n n N} by accepting state. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 9 / 22 Grammars Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 10 / 22 Grammars Goal 1 Stack automata 2 Grammars Problem : Express languages with the same expressivity as stack automata. use grammars Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 11 / 22 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 12 / 22

19 Grammars Grammars General grammars Grammars Grammar rule A grammar rule (production rule) is of the form w w where w and w are words. A grammar is a set of rules. Grammar A grammar is composed of : A finite set N of non terminal symbols A finite set Σ of terminal symbols (disjoint from N) A finite set of production rules, each rule of the form w w where w is a word on Σ N with at least one letter of N. w is a word on Σ N. A start symbol S N. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 13 / 22 Grammars Grammars Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 14 / 22 Associated Language Grammars Example : S asb S ε Derivation G a grammar defines the relation : x G y iff u, v, p, qx = upv and y = uqv and (p q) P is a grammar with N =... and... A grammar describes a language (the set of words on Σ that can be derived from the start symbol). Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 15 / 22 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 16 / 22

20 Grammars Grammars Examples Context-free grammars S asb S ε The grammar defines the language {a n b n, n N} S absc S abc Context-free grammar A CF-grammar is a grammar where all production rules are of the form N (Σ N). Ba ab Bb bb The grammar defines the language {a n b n c n, n N} Exercises Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 17 / 22 Grammars Example of CF-grammar Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 18 / 22 Grammars Relationship between stack automata and grammars S S + S S S a The grammar defines a language of arithmetical expressions. Notion of derivation tree. Draw a derivation tree of a*a+a, of S+S! General result The context-free/algebraic languages are exactly the languages that are described by stack automata. The proof is not difficult. Exercises Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 19 / 22 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 20 / 22

21 Grammars Conclusion Some other results/definitions Summary Regular languages are algebraic languages, but not the converse. There exists normal forms for algebraic grammars A grammar can be ambiguous. Stack Automata or PushDown Automata are : Acceptors for context-free languages. But some languages are not context free. Non deterministic. for useful pointers Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 21 / 22 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 22 / 22

22 Laure Gonnord Polycopié d'informatique Fondamentale IMA4SC S Chapitre 3 Automates à compteurs et machines de turing Dans ce chapitre nous étudions des modèles plus proches de nos programmes habituels, les automates à compteurs, et introduisons le modèle couramment utilisé pour formaliser la notion de calcul, les machines de Turing. 22/58

23 Informatique Fondamentale IMA S8 Cours 3: Counter automata, Turing Machines and decidable problems Laure Gonnord III - Counter automata, Turing Machines and decidable problems Université Lille 1 - Polytech Lille 2013 Counter automata Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 2 / 30 Counter automata What for? 1 Counter automata 2 Programs 3 Turing Machines Express more than context-free languages! Give a way for automata to count more : include variables. 4 Decidability - Complexity Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 3 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 4 / 30

24 Counter automata Counter automata Example General definition cos(y) x x := x+1 k init k 1 x y y := y x true y := y +2 Counter Automata A finite number of counters (variables) A finite number of control points Transitions between them that operate on counters. The transition function is of the form g a (g is the guard, a is the action) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 5 / 30 How it works? 1/3 Counter automata Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 6 / 30 How it works? 2/3 Counter automata State A state is (q, σ) q is the current control point σ : V ar V al is a function that assigns a value (a real one or ) to all counters. Non deterministic/no notion of acceptance/notion of reachability. Given a state (q, σ), the next one is computed by the help of the transition function : enabled transitions are transition of the current control points where the current valuations of variables satisfy the guard. Pick one enabled transition, and compute the next state : (q, σ ). The new values for the variables are computed w.r.t. the action. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 7 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 8 / 30

25 Counter automata Counter automata How it works? 3/3 Example of an affine automata : y +2x 2 x := 2x+5 true x := 0;y := 0 x 1 x := x+1;y := 2y 4 k init k 1 k 2 What kind of systems? These automata are used to encode, for example : Simple systems (coffee machine,...) specifications Energy consumption of sensors : 400 µs mw Transmit mw Compute successive states. Exercises. Sleep 35.1 mw 332 µs mw Idle mw 144 µs mw 144 µs mw 100 µs 100 µs mw mw Receive mw Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 9 / 30 Counter automata Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 10 / 30 Programs What for? 1 Counter automata Some classical problems : Automatically finding invariants Reachability analysis Formula proving. (deterministic) Code generation. 2 Programs 3 Turing Machines 4 Decidability - Complexity Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 11 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 12 / 30

26 Programs Expressing programs as counter automata An example : x:=0;y:=0 while (x<=100) do read(b); if b then x:=x+2 else begin x:=x+1; y:=y+1; end; endif endwhile x 100 x := x+1 y := y +1 p in p p out (x,y) := (0,0) x 100 Some approximations are made (arrays, Boolean,... ) x 100 x := x+2 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 13 / 30 Programs Expressing properties of programs - 2 Automatically deriving bad states : Programs Expressing properties of programs Some (safety) properties of programs can be expressed inside the counter automaton : x 100 x := x+1 y := y +1 p in p p out (x,y) := (0,0) x 100 x 100 x := x+2 Encode the fact that state = p out y > 100 is bad Some modifications of the automaton can be automatically done. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 14 / 30 Programs Expressing programs as counter automata int j; char user[usersz]; for(j = 0; line[j]!= EOS; ++j) if (!strchr("-", line[j])) break; if(j == J && line[j] == ' ') { /* long list */ /* BUG! No bounds check. */ assert(usersz>=n-j,"badstate"); Pros : finding and proving program properties Cons : how do we define the operations? the fact that integers are encoded on bits? There is a need for a more accurate (not specialised) model! } r_strcpy (user, line + j); badstate is reachable. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 15 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 16 / 30

27 Turing Machines Turing Machines Turing Machine, def Counter automata 2 Programs 3 Turing Machines 4 Decidability - Complexity Turing Machine, Turing, 1935 A tape (infinite in both sides) : the memory. (it has a working alphabet which contains a blank symbol). A head : read/write symbols on the tape. A finite transition table (or function) A PushDown automaton which is more flexible. image credits : Wikipedia.org Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 17 / 30 Turing Machines Turing Machine, def - 2 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 18 / 30 An Example Turing Machines Turing Machine elements States (Q), initial state (q 0 ), final (accepting) states (F). One alphabet Γ for the tape. b Γ the blank letter. Transitions are finitely many : read the letter under the head, and then : Erase a symbol or write one under the head Move the head (read, write, or stays) The state can be modified. The transition function is : TM that decides if x is odd : (final State : q 4 ) State/char 0 1 B q 1 (q 1,0,R) (q 1,1,R) (q 2,B,L) q 2 (q 3,0,L) (q 4,1,L) Play on BBBBBBB11BBBBB and BBBBBBB10BBBBB A configuration is a tuple (word on the tape, position of the head, state). Adapted from : slide 4 Q Γ Q Γ {L, R, S} Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 19 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 20 / 30

28 Turing Machines Turing Machines Another Example Demo of a TM recognising a language : a n b n c n Program found here : General results 1/2 There exists Turing machines for the following languages : palindromes a n b n c n (non algebraic language) a i with i prime (non algebraic) a n2, with n 0 Turing machines are more powerful than all other models (we have seen yet) Decidable Languages A language that is recognised by a Turing Machine is said to be decidable. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 21 / 30 Turing Machines Accepting or computing Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 22 / 30 Another Example Turing Machines A TM can also compute functions TM that writes 1 if x is odd, 0 else (q 6 is final state) : State/char 0 1 B q 1 (q 1,0,R) (q 1,1,R) (q 2,B,L) q 2 (q 3,B,L) (q 4,B,L) q 3 (q 3,B,L) (q 3,B,L) (q 5,1,R) q 4 (q 4,B,L) (q 4,B,L) (q 5,0,R) q 5 (q 6,B,R) Demo of a TM computing the subtraction. Play on BBBBBBB11BBBBB and BBBBBBB10BBBBB Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 23 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 24 / 30

29 Turing Machines Decidability - Complexity General results 2/2 There exists Turing machines for the computation of : x x + 1 (x, y) x + y x x 2 all the functions you are able to write on computers Computable functions A function (defined for all its input) that is computable by a Turing Machine is said to be TM computable 1 Counter automata 2 Programs 3 Turing Machines 4 Decidability - Complexity A Model of what can be computed with machines. (Church Thesis) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 25 / 30 Decidability - Complexity Decidable - Semi-decidable languages Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 26 / 30 Complexity Decidability - Complexity If L is a language, L is decidable if there exists a Turing Machine (or an algorithm) that outputs for all w : 1 if w L else 0. Semi-decidable : 1 if w L else does not terminate equivalent definition for problems. Link with computational complexity : The number of steps in the execution of a TM gives the complexity in time, The number of seen squares in the execution of a TM gives the complexity in space. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 27 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 28 / 30

30 Decidability - Complexity Examples of undecidable problems The halting problem for TM or counter automata (for more that 2 counters) Given a program, does it loops? Is a given algebraic expression (with log, *, exp, sin, abs) equal to 0? (Richardson, 1968) The 10 th Hilbert Problem (Diophantine equations) Summary Turing Machines : Conclusion A model closed to programming languages. Non deterministic. Acceptors for decidable languages. But some languages are not decidable! (equivalently) Computes solutions to problems. But... Important fact Some common problems are undecidable! Counter automata : are a more simpler model have the same power of expression as Turing Machines. Reachability is undecidable too. But we can do approximations. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 29 / 30 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8SC 30 / 30

31 Laure Gonnord Polycopié d'informatique Fondamentale IMA4SC S Chapitre 4 Graphes, notions de NP-complétude Les graphes orent une modélisation intéressante de beaucoup de problèmes d'informatique. Nous abordons leur représentation machine et présentons rapidement les algorithmes classiques. Nous protons du modèle pour parler de complexité théorique, de problèmes diciles, et de NP-complétude Figure 4.1 Pillow talk, sous License Creative Commons Figure 4.2 Travelling salesman Problem, sous License Creative Commons 31/58

32 Informatique Fondamentale IMA S8 Cours 4 : graphs, problems and algorithms on graphs, (notions of) NP completeness Laure Gonnord Laure.Gonnord@polytech-lille.fr IV - Graphs, problems and algorithms on graphs, NP-completeness Université Lille 1 - Polytech Lille 2013 Some generalities on graphs 1 Some generalities on graphs Generalities and first definitions Internal representation 2 Paths finding - search, and applications 3 Algorithms specific to oriented graphs 4 More difficult problems on graphs 5 NP - completeness Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 2 / 64 Goal Model : Some generalities on graphs Generalities and first definitions relationships between objects ( I know him, This register is in conflict with with one, there is a road between these two towns ) classical problems of paths ( Do I have a friend that knows a friend... who knows the Dalai-Lama?, It is possible to go from this town to this another in less than 600 km?, how to get out of the labyrinth? ) 6 Docs Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 3 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 4 / 64

33 Some generalities on graphs Generalities and first definitions Some generalities on graphs Generalities and first definitions Who? Other classical problems Euler (1740) formalised the theory and the Konisberg problem : Problem : compute an eulerian path. Source (fr) : The travelling salesman problem : TSP Task scheduling (on parallel machines or not!), the PERT method. Coloring maps Covering (telecom) trees Minimal paths... Graphs are everywhere. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 5 / 64 Some generalities on graphs Generalities and first definitions General definition Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 6 / 64 Some generalities on graphs Generalities and first definitions Other definitions Graph A finite set of vertices (a vertex) : V A finite set of edges. E V V v 1 e 1 e 3 v3 Non Oriented Graph iff (v1, v2), (v1, v2) E (v2, v1) E. Tree (non oriented acyclic connex) - Forest. Directed Acyclic Graph : DAG. Oriented Graph with no cycle. trees are dags! v1 v3 v2 v2 v4 A simplier model than the previous ones! Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 7 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 8 / 64

34 Some generalities on graphs Internal representation Some generalities on graphs Internal representation Sources Adjacency matrix Picture and Java codes from If the graph is oriented, then the matrix is NOT symmetric Memory complexity : O(V 2 ) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 9 / 64 Some generalities on graphs Internal representation Adjacency matrix - Java Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 10 / 64 Some generalities on graphs Internal representation Array of lists boolean [ ] [ ] m; Graph ( i n t n ) { m = new boolean [ n ] [ n ] ; for ( i n t i = 0; i < n ; ++ i ) for ( i n t j = 0; j < n ; ++ j ) m[ x ] [ y ] = f a l s e ; } s t a t i c void addedge ( Graph g, i n t x, i n t y ) { g.m[ x ] [ y ] = t r u e ; g.m[ y ] [ x ] = t r u e / / only i f non o r i e n t e d } Memory complexity : O(V + E) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 11 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 12 / 64

35 Array of lists - Java Some generalities on graphs Internal representation Paths finding - search, and applications 1 Some generalities on graphs } L i s t e [ ] succ ; Graph ( i n t n ) { succ = new L i s t e [ n ] ; } s t a t i c void addedge ( Graph g, i n t x, i n t y ) { g. succ [ x ] = new L i s t e ( y, g. succ [ x ] ) ; / / i f non o r i e n t e d also modify g. succ [ y ]! } 2 Paths finding - search, and applications Looking for all nodes Connexity Topological Sort 3 Algorithms specific to oriented graphs 4 More difficult problems on graphs 5 NP - completeness 6 Docs Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 13 / 64 Paths finding - search, and applications Looking for all nodes Search Algorithms Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 14 / 64 Paths finding - search, and applications Looking for all nodes Deep First Search on Graphs! Translation problem! (en) Search Algorithms - (fr) Parcours de Graphes Reminder : search/do algorithm on a binary tree : On graphs, there can be cycles! 1 If the tree is not empty, do f(root). 2 recursively apply the function on the left sub-tree 3 recursively apply the function on the right sub-tree Deep-First Search Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 15 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 16 / 64

36 Paths finding - search, and applications Looking for all nodes Paths finding - search, and applications Looking for all nodes Deep First Search on Graphs - Java Breadth First Search on Graphs s t a t i c i n t [ ] num; / / numbering the edges according to the v i s i t i n g order s t a t i c void v i s i t e r ( Graphe g ) { i n t n = g. succ. length ; num = new i n t [ n ] ; numordre = 1; for ( i n t x = 0; x < n ; ++x ) num[ x ] = 1; / / 1 = not seen for ( i n t x = 0; x < n ; ++x ) i f (num[ x ] == 1) dfs ( g, x ) ; } s t a t i c void dfs ( Graphe g, i n t x ) { num [ x ] = ++numordre ; for ( L i s t e l s = g. succ [ x ] ; l s!= n u l l ; l s = l s. s u i v a n t ) { i n t y = l s. v a l ; i f (num[ y ] == 1) dfs ( g, y ) ; } } Complexity = O(V + E). Tarjan [1972] Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 17 / 64 Conventions Paths finding - search, and applications Looking for all nodes BLANC = not (yet) processed NOIR = has been processed GRIS = being processed f i n a l s t a t i c i n t BLANC = 0, GRIS = 1, NOIR = 2; s t a t i c i n t [ ] couleur ; Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 18 / 64 Paths finding - search, and applications Looking for all nodes Breadth First Search on Graphs - Java i n t n = g. succ. length ; couleur = new i n t [ n ] ; FIFO f = new FIFO ( n ) ; for ( i n t x = 0; x < n ; ++x ) couleur [ x ] = BLANC; for ( i n t x = 0; x < n ; ++x ) i f ( couleur [ x ] == BLANC) { FIFO. a j o u t e r ( f, x ) ; couleur [ x ] = GRIS ; bfs ( g, f ) ; } s t a t i c void bfs ( Graphe g, FIFO f ) { while (! f. vide ( ) ) { i n t x = FIFO. supprimer ( f ) ; for ( L i s t e l s = g. succ [ x ] ; l s!= n u l l ; l s = l s. s u i v a n t ) { i n t y = l s. v a l ; i f ( couleur [ y ] == BLANC) { FIFO. a j o u t e r ( f, y ) ; couleur [ y ] = GRIS ; } couleur [ x ] = NOIR ; } } } Complexity? Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 19 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 20 / 64

37 Paths finding - search, and applications Looking for all nodes Paths finding - search, and applications Connexity Application : Labyrinth Finds exit, ie a path from d to s? } couleur [ d ] = GRIS ; i f ( d == s ) return new L i s t e ( d, n u l l ) ; for ( L i s t e l s = g. succ [ d ] ; l s!= n u l l ; l s = l s. s u i v a n t ) { i n t x = l s. v a l ; i f (num[ x ] == BLANC) { L i s t e r = chemin ( g, x, s ) ; i f ( r!= n u l l ) return new L i s t e ( d, r ) ; } } return n u l l ; Definition - Connex Component Connex component A connex component is a maximal set of connected vertices. Exercise : Algorithm for computing CCs. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 21 / 64 Paths finding - search, and applications Connexity Definition - Connex Graph Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 22 / 64 Paths finding - search, and applications Topological Sort Other Algorithms There exists variants of DFS algo to : Compute Cover Forets (in bold in the picture) : Connex graph A graph is connex if it has only one connex component. Exercise : Algorithm that tests the connexity of a graph. Detect Cycles. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 23 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 24 / 64

38 Algorithms specific to oriented graphs Algorithms specific to oriented graphs Topological sorting of a DAG 1 Some generalities on graphs 2 Paths finding - search, and applications 3 Algorithms specific to oriented graphs 4 More difficult problems on graphs 5 NP - completeness 6 Docs Give a list of vertices in an order compatible with the DAG order : v i < v j v j v i (total order from a partial header). Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 25 / 64 Algorithms specific to oriented graphs Topological sorting of a DAG - Example Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 26 / 64 Algorithms specific to oriented graphs Topological sorting of a DAG - implementation If we know an entrant node, a dfs gives the result. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 27 / 64 f i n a l s t a t i c i n t BLANC = 0, GRIS = 1, NOIR = 2; s t a t i c L i s t e afaire ( Graphe g, i n t x ) { i n t n = g. succ. length ; i n t [ ] couleur = new i n t [ n ] ; for ( i n t x = 0; x < n ; ++x ) couleur [ x ] = BLANC; return dfs ( g, x, n u l l, couleur ) ; } s t a t i c L i s t e dfs ( Graphe g, i n t x, L i s t e r, i n t [ ] couleur ) { couleur [ x ] = GRIS ; for ( L i s t e l s = g. succ [ x ] ; l s!= n u l l ; l s = l s. s u i v a n t ) { i n t y = l s. v a l ; i f ( couleur [ y ] == BLANC) r = dfs ( g, y, r, couleur ) ; } return new L i s t e ( x, r ) ; } dfs here returns a list. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 28 / 64

39 Algorithms specific to oriented graphs Topological sorting of a DAG - Applications Transitive closure Algorithms specific to oriented graphs instruction scheduling cell evaluation in spreadsheets order of compilation tasks (Makefiles) symbol dependencies in linkers sheduling in project managements (PERT, 1960) The graph G + = (V, E + ) of the transitive closure of G = (V, E) is such that E + is the smallest set verifying : E E + (x, y) E + and (y, z) E + (x, z) E + Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 29 / 64 Algorithms specific to oriented graphs Algorithm for Transitive closure Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 30 / 64 Algorithms specific to oriented graphs Definition of oriented valuated graph Valuated graph It s a graph with a function d : V V N called distance. If E is the adjacency matrix : E + = E + E E n 1. An algorithm in O(n 4 ). Is it possible to have a better complexity? Yes (Warshall, in O(n 3 ), see later). G is represented by an adjacency matrix with integer values, or + if there is no edge. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 31 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 32 / 64

40 Algorithms specific to oriented graphs The shortest path problem Algorithms specific to oriented graphs Multiple Source Shortest Path with dynamic programming -1 Given G, find a path whose sum of distances is minimal! Between all the vertices! Floyd-Warshall algorithm Principle : Let d k x,y be the minimal distance between x and y passing through vertices whose number is < k. Then d 0 x,y = d x,y and d k x,y = min{d k 1 x,y, d k 1 x,k + dk 1 k,y } more variants on Store all these temporary distances. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 33 / 64 Algorithms specific to oriented graphs Multiple Source Shortest Path with dynamic programming -2 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 34 / 64 Algorithms specific to oriented graphs Simple Source Shortest Path s t a t i c Graphe pluscourtschemins ( Graphe g ) { i n t n = g. d. length ; Graphe gplus = copiegraphe ( g ) ; for ( i n t k = 0; k < n ; ++k ) for ( i n t x = 0; x < n ; ++x ) for ( i n t y = 0; y < n ; ++y ) gplus. d [ x ] [ y ] = Math. min ( gplus. d [ x ] [ y ], gplus. d [ x ] [ k ] + gplus. d [ k ] [ y ] ) ; return gplus ; } All d are > 0 : Dijkstra, 1959 Negative distances : Bellman Ford 1960 Routing algorithms (Bellman uses only local information). Complexity O(n 3 ), space O(n 2 ). Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 35 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 36 / 64

41 More difficult problems on graphs More difficult problems on graphs Eulerian and Hamiltonian paths 1 Some generalities on graphs 2 Paths finding - search, and applications 3 Algorithms specific to oriented graphs 4 More difficult problems on graphs Eulerian/Hamiltonian Path An Eulerian path : each edge is seen only once. An Hamiltonien path : each node... 5 NP - completeness 6 Docs Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 37 / 64 More difficult problems on graphs Hamiltonian Tour, one solution Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 38 / 64 More difficult problems on graphs Application 1 : Knight s Tour Extend a path until not possible Backtrack one time, and try with another neighbour And so on. Worst case complexity time : exponential in n Is it possible to make a Knight s tour? «The knight is placed on the empty board and, moving according to the rules of chess, must visit each square exactly once.» A variant of the Hamiltonian tour that can be solved in polynomial time. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 39 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 40 / 64

42 More difficult problems on graphs The Travelling Salesman Problem More difficult problems on graphs Travelling Salesman Problem - 2 A (non-polynomial) algorithm for this problem : Transform into a linear programming problem with integers Solve it with the simplex! This algorithm is exponential in the size of the graph with valuated (non oriented) graph. Find an hamiltonian cycle of minimum weight Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 41 / 64 More difficult problems on graphs Graph Coloring Problem Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 42 / 64 More difficult problems on graphs Graph Coloring Problem - 2 Are you able to design a polynomial algorithm? Application to the register allocation in compilers. The sudoku problem (9-coloring of a 81-vertices graph) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 43 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 44 / 64

43 More difficult problems on graphs NP - completeness Graph Coloring Problem - 3 We do not know any polynomial algorithm for this problem. 1 Some generalities on graphs 2 Paths finding - search, and applications 3 Algorithms specific to oriented graphs 4 More difficult problems on graphs 5 NP - completeness 6 Docs Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 45 / 64 Complexity NP - completeness Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 46 / 64 P Problems NP - completeness The complexity of an implementation / an algorithm is linked to Turing machines : The number of steps in the execution of a TM gives the complexity in time, The number of seen squares in the execution of a TM gives the complexity in space. We can replace the TM by a C implementation. P A problem (or a language) belongs to P if there exists a deterministic Turing Machine that gives the result in polynomial time. there is a polynom p such that for all entry x, the Turing machine stops (with the good result) in less than p( x ) steps. Example : L = a n b n c n, the TM of the previous course checks any a i b i c i in O(n) steps Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 47 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 48 / 64

44 NP - completeness NP - completeness P Problems NP Problems Integer multiplication Eulerian tour (each edge once) Linear programming (recall that polynomial diophantine equations are undecidible.) Primality test NP A problem (or a language) belongs to NP if there exists a deterministic Turing Machine that checks the result in polynomial time. Example : there exists a TM that is able to check if a given path is an hamiltonien tour, in polynomial time. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 49 / 64 NP - completeness NP Problems - Examples Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 50 / 64 NP vs P - some facts NP - completeness Factoring 3-SAT (formulae in CNF with 3 litterals on each term) Hamiltonian tour 3-colorability If a problem belongs to NP, then there exists an exponential brute-force deterministic algorithm to solve it (easy to prove) P NP (trivial) P = NP? P NP? Open question! Problem of the millenium! Is finding more difficult that verifying? Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 51 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 52 / 64

45 NP - completeness NP-complete problems - 1 NP - completeness NP-complete problems - 2 Given a problem : if we find a polynomial algorithm P if we find a polynomial time checking algorithm NP, but we want to know more : it it really hard to solve it? is it worth looking for a better algorithm? The key notion is the notion of polynomial reduction Polynomial reduction of problems Given two problems P 1 and P 2, P 1 reduces polynomially to P 2 if there exists an f such that : f is polynomial x 1 solution of P 1 iff f(x 1 ) solution of P 2. Example : Hamiltonian circuit is polynomially reductible to TSP. Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 53 / 64 NP - completeness NP-complete problems - 3 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 54 / 64 NP - completeness NP-complete problems - 4 The most difficult problems in NP. All problems in NPC are computationally equivalent in the sense that, if one problem is easy, all the problems in the class are easy. Therefore, if one problem in NPC turns out to be in P, then P=NP Reminder : we want to characterise the most difficult problems in NP. NP-complete A problem is said to be NP-complete if : It belongs to NP All other problems in NP reduce polynomially to it. In other words, if we solve any NP-complete in polynomial time, we have proved P = NP (and we become rich) Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 55 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 56 / 64

46 NP - completeness NP-complete problems - 4 NP - completeness NP-complete problems - The historical example Problem : how to prove that a problem is NP-complete? The very first one is hard to prove Then, we use the following result : If two problems / languages L 1 and L 2 belong to NP and L 1 is NP-complete, and L 1 reduces polynomially to L 2, then L 2 is NP-complete. Pick one NP complete problem and try to reduce it to your problem. SATISFIABILITY is NP-complete (Cook, 1971) SAT reduces polynomially to 3SAT 3SAT reduces polynomially to Vertex Cover Vertex Cover reduces polynomially to Hamiltonian circuit So Hamiltonian circuit, then TSP are also NP-complete problems Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 57 / 64 NP - completeness Some NP-complete (common) problems Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 58 / 64 Conclusion - 1 NP - completeness Some classical examples : Hamiltonian cycle and TSP Graph Coloring Problem Vertex cover Knapsack (integer) Flow shop problem Sudoku The book : Computers and Intractability : A Guide to the Theory of NP-Completeness. A short list on the french webpage : NP-complets Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 59 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 60 / 64

47 NP - completeness Docs Conclusion Some generalities on graphs 2 Paths finding - search, and applications Knowing that a given problem is NP complete is just the beginning : handle less general classes of inputs compute less precise solutions 3 Algorithms specific to oriented graphs 4 More difficult problems on graphs 5 NP - completeness 6 Docs Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 61 / 64 More docs on graphs Docs Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 62 / 64 More docs on complexity Docs In french : graphes/cours/cours_graphes.pdf or type cours de Théorie des graphes in Google In english : an interactive tutorial here : utm.edu/cgi-bin/caldwell/tutor/graph/intro. (en) The theorical book Graph Theory, R. Diestel (electronic version : The Book : computers and intractability, a guide to the theory of NP completeness, by Garey/Johnson (en) e-book for algorithms : http: //code.google.com/p/graph-theory-algorithms-book/ Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 63 / 64 Laure Gonnord (Lille1/Polytech) Informatique Fondamentale IMA S S8-SC 64 / 64

Informatique Fondamentale IMA S8

Informatique Fondamentale IMA S8 Informatique Fondamentale IMA S8 Cours 4 : graphs, problems and algorithms on graphs, (notions of) NP completeness Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@polytech-lille.fr Université

More information

CAPES MI. Turing Machines and decidable problems. Laure Gonnord

CAPES MI. Turing Machines and decidable problems. Laure Gonnord CAPES MI Turing Machines and decidable problems Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@univ-lyon1.fr Université Claude Bernard Lyon1 2017 Motivation 1 Motivation 2 Turing Machines

More information

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65 Undecidable Problems Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, 2018 1/ 65 Algorithmically Solvable Problems Let us assume we have a problem P. If there is an algorithm solving

More information

Final exam study sheet for CS3719 Turing machines and decidability.

Final exam study sheet for CS3719 Turing machines and decidability. Final exam study sheet for CS3719 Turing machines and decidability. A Turing machine is a finite automaton with an infinite memory (tape). Formally, a Turing machine is a 6-tuple M = (Q, Σ, Γ, δ, q 0,

More information

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages COMP/MATH 300 Topics for Spring 2017 June 5, 2017 Review and Regular Languages Exam I I. Introductory and review information from Chapter 0 II. Problems and Languages A. Computable problems can be expressed

More information

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch] NP-Completeness Andreas Klappenecker [based on slides by Prof. Welch] 1 Prelude: Informal Discussion (Incidentally, we will never get very formal in this course) 2 Polynomial Time Algorithms Most of the

More information

Introduction: Computer Science is a cluster of related scientific and engineering disciplines concerned with the study and application of computations. These disciplines range from the pure and basic scientific

More information

3130CIT Theory of Computation

3130CIT Theory of Computation GRIFFITH UNIVERSITY School of Computing and Information Technology 3130CIT Theory of Computation Final Examination, Semester 2, 2006 Details Total marks: 120 (40% of the total marks for this subject) Perusal:

More information

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k. Complexity Theory Problems are divided into complexity classes. Informally: So far in this course, almost all algorithms had polynomial running time, i.e., on inputs of size n, worst-case running time

More information

(a) Definition of TMs. First Problem of URMs

(a) Definition of TMs. First Problem of URMs Sec. 4: Turing Machines First Problem of URMs (a) Definition of the Turing Machine. (b) URM computable functions are Turing computable. (c) Undecidability of the Turing Halting Problem That incrementing

More information

Artificial Intelligence. 3 Problem Complexity. Prof. Dr. Jana Koehler Fall 2016 HSLU - JK

Artificial Intelligence. 3 Problem Complexity. Prof. Dr. Jana Koehler Fall 2016 HSLU - JK Artificial Intelligence 3 Problem Complexity Prof. Dr. Jana Koehler Fall 2016 Agenda Computability and Turing Machines Tractable and Intractable Problems P vs. NP Decision Problems Optimization problems

More information

NP-completeness. Chapter 34. Sergey Bereg

NP-completeness. Chapter 34. Sergey Bereg NP-completeness Chapter 34 Sergey Bereg Oct 2017 Examples Some problems admit polynomial time algorithms, i.e. O(n k ) running time where n is the input size. We will study a class of NP-complete problems

More information

Part I: Definitions and Properties

Part I: Definitions and Properties Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States

More information

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar Turing Machine A Turing machine is an abstract representation of a computing device. It consists of a read/write

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 15 Ana Bove May 17th 2018 Recap: Context-free Languages Chomsky hierarchy: Regular languages are also context-free; Pumping lemma

More information

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES Contents i SYLLABUS UNIT - I CHAPTER - 1 : AUT UTOMA OMATA Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 2 : FINITE AUT UTOMA OMATA An Informal Picture of Finite Automata,

More information

Complexity: Some examples

Complexity: Some examples Algorithms and Architectures III: Distributed Systems H-P Schwefel, Jens M. Pedersen Mm6 Distributed storage and access (jmp) Mm7 Introduction to security aspects (hps) Mm8 Parallel complexity (hps) Mm9

More information

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY No part of this publication may be reproduced or distributed in any form or any means, electronic, mechanical, photocopying, or otherwise without the prior permission of the author. GATE SOLVED PAPER Computer

More information

Data Structures in Java

Data Structures in Java Data Structures in Java Lecture 21: Introduction to NP-Completeness 12/9/2015 Daniel Bauer Algorithms and Problem Solving Purpose of algorithms: find solutions to problems. Data Structures provide ways

More information

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu Part 4 out of 5 ETH Zürich (D-ITET) October, 12 2017 Last week, we showed the equivalence of DFA, NFA and REX

More information

Limitations of Algorithm Power

Limitations of Algorithm Power Limitations of Algorithm Power Objectives We now move into the third and final major theme for this course. 1. Tools for analyzing algorithms. 2. Design strategies for designing algorithms. 3. Identifying

More information

CPSC 421: Tutorial #1

CPSC 421: Tutorial #1 CPSC 421: Tutorial #1 October 14, 2016 Set Theory. 1. Let A be an arbitrary set, and let B = {x A : x / x}. That is, B contains all sets in A that do not contain themselves: For all y, ( ) y B if and only

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY THURSDAY APRIL 3 REVIEW for Midterm TUESDAY April 8 Definition: A Turing Machine is a 7-tuple T = (Q, Σ, Γ, δ, q, q accept, q reject ), where: Q is a

More information

Automata Theory (2A) Young Won Lim 5/31/18

Automata Theory (2A) Young Won Lim 5/31/18 Automata Theory (2A) Copyright (c) 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Computational complexity theory

Computational complexity theory Computational complexity theory Introduction to computational complexity theory Complexity (computability) theory deals with two aspects: Algorithm s complexity. Problem s complexity. References S. Cook,

More information

The purpose here is to classify computational problems according to their complexity. For that purpose we need first to agree on a computational

The purpose here is to classify computational problems according to their complexity. For that purpose we need first to agree on a computational 1 The purpose here is to classify computational problems according to their complexity. For that purpose we need first to agree on a computational model. We'll remind you what a Turing machine is --- you

More information

Complexity Theory of Polynomial-Time Problems

Complexity Theory of Polynomial-Time Problems Complexity Theory of Polynomial-Time Problems Lecture 1: Introduction, Easy Examples Karl Bringmann and Sebastian Krinninger Audience no formal requirements, but: NP-hardness, satisfiability problem, how

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2016 http://cseweb.ucsd.edu/classes/sp16/cse105-ab/ Today's learning goals Sipser Ch 3.3, 4.1 State and use the Church-Turing thesis. Give examples of decidable problems.

More information

Final Exam Comments. UVa - cs302: Theory of Computation Spring < Total

Final Exam Comments. UVa - cs302: Theory of Computation Spring < Total UVa - cs302: Theory of Computation Spring 2008 Final Exam Comments < 50 50 59 60 69 70 79 80 89 90 94 95-102 Total 2 6 8 22 16 16 12 Problem 1: Short Answers. (20) For each question, provide a correct,

More information

Turing Machines. 22c:135 Theory of Computation. Tape of a Turing Machine (TM) TM versus FA, PDA

Turing Machines. 22c:135 Theory of Computation. Tape of a Turing Machine (TM) TM versus FA, PDA Turing Machines A Turing machine is similar to a finite automaton with supply of unlimited memory. A Turing machine can do everything that any computing device can do. There exist problems that even a

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation CFL Hierarchy CFL Decision Problems Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Anything else I have included some slides online

More information

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness Harry Lewis November 19, 2013 Reading: Sipser 7.4, 7.5. For culture : Computers and Intractability: A Guide to the Theory

More information

Introduction to Turing Machines. Reading: Chapters 8 & 9

Introduction to Turing Machines. Reading: Chapters 8 & 9 Introduction to Turing Machines Reading: Chapters 8 & 9 1 Turing Machines (TM) Generalize the class of CFLs: Recursively Enumerable Languages Recursive Languages Context-Free Languages Regular Languages

More information

Mm7 Intro to distributed computing (jmp) Mm8 Backtracking, 2-player games, genetic algorithms (hps) Mm9 Complex Problems in Network Planning (JMP)

Mm7 Intro to distributed computing (jmp) Mm8 Backtracking, 2-player games, genetic algorithms (hps) Mm9 Complex Problems in Network Planning (JMP) Algorithms and Architectures II H-P Schwefel, Jens M. Pedersen Mm6 Advanced Graph Algorithms (hps) Mm7 Intro to distributed computing (jmp) Mm8 Backtracking, 2-player games, genetic algorithms (hps) Mm9

More information

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits Chris Calabro January 13, 2016 1 RAM model There are many possible, roughly equivalent RAM models. Below we will define one in the fashion

More information

CS6901: review of Theory of Computation and Algorithms

CS6901: review of Theory of Computation and Algorithms CS6901: review of Theory of Computation and Algorithms Any mechanically (automatically) discretely computation of problem solving contains at least three components: - problem description - computational

More information

Introduction to Complexity Theory

Introduction to Complexity Theory Introduction to Complexity Theory Read K & S Chapter 6. Most computational problems you will face your life are solvable (decidable). We have yet to address whether a problem is easy or hard. Complexity

More information

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University NP-Completeness CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Hard Graph Problems Hard means no known solutions with

More information

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata CISC 4090: Theory of Computation Chapter Regular Languages Xiaolan Zhang, adapted from slides by Prof. Werschulz Section.: Finite Automata Fordham University Department of Computer and Information Sciences

More information

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler Complexity Theory Complexity Theory VU 181.142, SS 2018 6. The Polynomial Hierarchy Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität Wien 15 May, 2018 Reinhard

More information

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1 CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY E. Amaldi Foundations of Operations Research Politecnico di Milano 1 Goal: Evaluate the computational requirements (this course s focus: time) to solve

More information

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181. Complexity Theory Complexity Theory Outline Complexity Theory VU 181.142, SS 2018 6. The Polynomial Hierarchy Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität

More information

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET Regular Languages and FA A language is a set of strings over a finite alphabet Σ. All languages are finite or countably infinite. The set of all languages

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be

More information

Computability and Complexity Theory

Computability and Complexity Theory Discrete Math for Bioinformatics WS 09/10:, by A Bockmayr/K Reinert, January 27, 2010, 18:39 9001 Computability and Complexity Theory Computability and complexity Computability theory What problems can

More information

Computational complexity theory

Computational complexity theory Computational complexity theory Introduction to computational complexity theory Complexity (computability) theory deals with two aspects: Algorithm s complexity. Problem s complexity. References S. Cook,

More information

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen Pushdown automata Twan van Laarhoven Institute for Computing and Information Sciences Intelligent Systems Version: fall 2014 T. van Laarhoven Version: fall 2014 Formal Languages, Grammars and Automata

More information

Introduction to Computational Complexity

Introduction to Computational Complexity Introduction to Computational Complexity Jiyou Li lijiyou@sjtu.edu.cn Department of Mathematics, Shanghai Jiao Tong University Sep. 24th, 2013 Computation is everywhere Mathematics: addition; multiplication;

More information

Comparison of several polynomial and exponential time complexity functions. Size n

Comparison of several polynomial and exponential time complexity functions. Size n Comparison of several polynomial and exponential time complexity functions Time complexity function n n 2 n 3 n 5 2 n 3 n Size n 10 20 30 40 50 60.00001.00002.00003.00004.00005.00006 second second second

More information

NP-Complete problems

NP-Complete problems NP-Complete problems NP-complete problems (NPC): A subset of NP. If any NP-complete problem can be solved in polynomial time, then every problem in NP has a polynomial time solution. NP-complete languages

More information

13.1 Nondeterministic Polynomial Time

13.1 Nondeterministic Polynomial Time CS125 Lecture 13 Fall 2016 13.1 Nondeterministic Polynomial Time Now we turn to incorporating nondeterminism in universal models of computation, namely Turing Machines and Word-RAMs. For Nondeterministic

More information

NP Complete Problems. COMP 215 Lecture 20

NP Complete Problems. COMP 215 Lecture 20 NP Complete Problems COMP 215 Lecture 20 Complexity Theory Complexity theory is a research area unto itself. The central project is classifying problems as either tractable or intractable. Tractable Worst

More information

CS 583: Algorithms. NP Completeness Ch 34. Intractability

CS 583: Algorithms. NP Completeness Ch 34. Intractability CS 583: Algorithms NP Completeness Ch 34 Intractability Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Standard working

More information

Chapter 2 Algorithms and Computation

Chapter 2 Algorithms and Computation Chapter 2 Algorithms and Computation In this chapter, we first discuss the principles of algorithm and computation in general framework, common both in classical and quantum computers, then we go to the

More information

Theory of Computation. Theory of Computation

Theory of Computation. Theory of Computation Theory of Computation Theory of Computation What is possible to compute? We can prove that there are some problems computers cannot solve There are some problems computers can theoretically solve, but

More information

Computer Science. Questions for discussion Part II. Computer Science COMPUTER SCIENCE. Section 4.2.

Computer Science. Questions for discussion Part II. Computer Science COMPUTER SCIENCE. Section 4.2. COMPUTER SCIENCE S E D G E W I C K / W A Y N E PA R T I I : A L G O R I T H M S, T H E O R Y, A N D M A C H I N E S Computer Science Computer Science An Interdisciplinary Approach Section 4.2 ROBERT SEDGEWICK

More information

CSCI 1590 Intro to Computational Complexity

CSCI 1590 Intro to Computational Complexity CSCI 59 Intro to Computational Complexity Overview of the Course John E. Savage Brown University January 2, 29 John E. Savage (Brown University) CSCI 59 Intro to Computational Complexity January 2, 29

More information

CSCI3390-Lecture 14: The class NP

CSCI3390-Lecture 14: The class NP CSCI3390-Lecture 14: The class NP 1 Problems and Witnesses All of the decision problems described below have the form: Is there a solution to X? where X is the given problem instance. If the instance is

More information

Advanced topic: Space complexity

Advanced topic: Space complexity Advanced topic: Space complexity CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2016 1/28 Review: time complexity We have looked at how long it takes to

More information

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20 NP-complete problems CSE 101: Design and Analysis of Algorithms Lecture 20 CSE 101: Design and analysis of algorithms NP-complete problems Reading: Chapter 8 Homework 7 is due today, 11:59 PM Tomorrow

More information

NP Completeness and Approximation Algorithms

NP Completeness and Approximation Algorithms Winter School on Optimization Techniques December 15-20, 2016 Organized by ACMU, ISI and IEEE CEDA NP Completeness and Approximation Algorithms Susmita Sur-Kolay Advanced Computing and Microelectronic

More information

Show that the following problems are NP-complete

Show that the following problems are NP-complete Show that the following problems are NP-complete April 7, 2018 Below is a list of 30 exercises in which you are asked to prove that some problem is NP-complete. The goal is to better understand the theory

More information

CS3719 Theory of Computation and Algorithms

CS3719 Theory of Computation and Algorithms CS3719 Theory of Computation and Algorithms Any mechanically (automatically) discretely computation of problem solving contains at least three components: - problem description - computational tool - analysis

More information

NP-Completeness. Algorithmique Fall semester 2011/12

NP-Completeness. Algorithmique Fall semester 2011/12 NP-Completeness Algorithmique Fall semester 2011/12 1 What is an Algorithm? We haven t really answered this question in this course. Informally, an algorithm is a step-by-step procedure for computing a

More information

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University Intelligent Agents Formal Characteristics of Planning Ute Schmid Cognitive Systems, Applied Computer Science, Bamberg University Extensions to the slides for chapter 3 of Dana Nau with contributions by

More information

CP405 Theory of Computation

CP405 Theory of Computation CP405 Theory of Computation BB(3) q 0 q 1 q 2 0 q 1 1R q 2 0R q 2 1L 1 H1R q 1 1R q 0 1L Growing Fast BB(3) = 6 BB(4) = 13 BB(5) = 4098 BB(6) = 3.515 x 10 18267 (known) (known) (possible) (possible) Language:

More information

Computational Models Lecture 8 1

Computational Models Lecture 8 1 Computational Models Lecture 8 1 Handout Mode Ronitt Rubinfeld and Iftach Haitner. Tel Aviv University. May 11/13, 2015 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

More information

Chapter 5. Finite Automata

Chapter 5. Finite Automata Chapter 5 Finite Automata 5.1 Finite State Automata Capable of recognizing numerous symbol patterns, the class of regular languages Suitable for pattern-recognition type applications, such as the lexical

More information

Computational Models - Lecture 4

Computational Models - Lecture 4 Computational Models - Lecture 4 Regular languages: The Myhill-Nerode Theorem Context-free Grammars Chomsky Normal Form Pumping Lemma for context free languages Non context-free languages: Examples Push

More information

ECS 120 Lesson 15 Turing Machines, Pt. 1

ECS 120 Lesson 15 Turing Machines, Pt. 1 ECS 120 Lesson 15 Turing Machines, Pt. 1 Oliver Kreylos Wednesday, May 2nd, 2001 Before we can start investigating the really interesting problems in theoretical computer science, we have to introduce

More information

NP-Complete Problems. More reductions

NP-Complete Problems. More reductions NP-Complete Problems More reductions Definitions P: problems that can be solved in polynomial time (typically in n, size of input) on a deterministic Turing machine Any normal computer simulates a DTM

More information

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA. Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA NP Completeness Susmita Sur-Kolay Advanced Computing and Microelectronics Unit

More information

Complexity, P and NP

Complexity, P and NP Complexity, P and NP EECS 477 Lecture 21, 11/26/2002 Last week Lower bound arguments Information theoretic (12.2) Decision trees (sorting) Adversary arguments (12.3) Maximum of an array Graph connectivity

More information

MACHINE COMPUTING. the limitations

MACHINE COMPUTING. the limitations MACHINE COMPUTING the limitations human computing stealing brain cycles of the masses word recognition: to digitize all printed writing language education: to translate web content games with a purpose

More information

Theory of Computation - Module 4

Theory of Computation - Module 4 Theory of Computation - Module 4 Syllabus Turing Machines Formal definition Language acceptability by TM TM as acceptors, Transducers - designing of TM- Two way infinite TM- Multi tape TM - Universal Turing

More information

CS4026 Formal Models of Computation

CS4026 Formal Models of Computation CS4026 Formal Models of Computation Turing Machines Turing Machines Abstract but accurate model of computers Proposed by Alan Turing in 1936 There weren t computers back then! Turing s motivation: find

More information

CS 241 Analysis of Algorithms

CS 241 Analysis of Algorithms CS 241 Analysis of Algorithms Professor Eric Aaron Lecture T Th 9:00am Lecture Meeting Location: OLB 205 Business Grading updates: HW5 back today HW7 due Dec. 10 Reading: Ch. 22.1-22.3, Ch. 25.1-2, Ch.

More information

Most General computer?

Most General computer? Turing Machines Most General computer? DFAs are simple model of computation. Accept only the regular languages. Is there a kind of computer that can accept any language, or compute any function? Recall

More information

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK COMS11700 Undecidability Department of Computer Science, University of Bristol Bristol, UK 4 April 2014 COMS11700: Undecidability Slide 1/29 Decidability We are particularly interested in Turing machines

More information

X-machines - a computational model framework.

X-machines - a computational model framework. Chapter 2. X-machines - a computational model framework. This chapter has three aims: To examine the main existing computational models and assess their computational power. To present the X-machines as

More information

Theory of computation: initial remarks (Chapter 11)

Theory of computation: initial remarks (Chapter 11) Theory of computation: initial remarks (Chapter 11) For many purposes, computation is elegantly modeled with simple mathematical objects: Turing machines, finite automata, pushdown automata, and such.

More information

Theory of computation: initial remarks (Chapter 11)

Theory of computation: initial remarks (Chapter 11) Theory of computation: initial remarks (Chapter 11) For many purposes, computation is elegantly modeled with simple mathematical objects: Turing machines, finite automata, pushdown automata, and such.

More information

Lecture 17: Language Recognition

Lecture 17: Language Recognition Lecture 17: Language Recognition Finite State Automata Deterministic and Non-Deterministic Finite Automata Regular Expressions Push-Down Automata Turing Machines Modeling Computation When attempting to

More information

Theory of Computation Turing Machine and Pushdown Automata

Theory of Computation Turing Machine and Pushdown Automata Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type

More information

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1 NP CS 320, Fall 2017 Dr. Geri Georg, Instructor georg@colostate.edu 320 NP 1 NP Complete A class of problems where: No polynomial time algorithm has been discovered No proof that one doesn t exist 320

More information

Theory of Computation Lecture Notes. Problems and Algorithms. Class Information

Theory of Computation Lecture Notes. Problems and Algorithms. Class Information Theory of Computation Lecture Notes Prof. Yuh-Dauh Lyuu Dept. Computer Science & Information Engineering and Department of Finance National Taiwan University Problems and Algorithms c 2004 Prof. Yuh-Dauh

More information

Theory of Computation

Theory of Computation Theory of Computation Lecture #2 Sarmad Abbasi Virtual University Sarmad Abbasi (Virtual University) Theory of Computation 1 / 1 Lecture 2: Overview Recall some basic definitions from Automata Theory.

More information

Complexity - Introduction + Complexity classes

Complexity - Introduction + Complexity classes Complexity - Introduction + Complexity classes Computability - is a problem solvable? Part I: via Turing machines Part II: via Church s Lambda calculus..now.. Part III: Complexity is concerned with how

More information

Theory Bridge Exam Example Questions

Theory Bridge Exam Example Questions Theory Bridge Exam Example Questions Annotated version with some (sometimes rather sketchy) answers and notes. This is a collection of sample theory bridge exam questions. This is just to get some idea

More information

Unit 1A: Computational Complexity

Unit 1A: Computational Complexity Unit 1A: Computational Complexity Course contents: Computational complexity NP-completeness Algorithmic Paradigms Readings Chapters 3, 4, and 5 Unit 1A 1 O: Upper Bounding Function Def: f(n)= O(g(n)) if

More information

The Turing Machine. Computability. The Church-Turing Thesis (1936) Theory Hall of Fame. Theory Hall of Fame. Undecidability

The Turing Machine. Computability. The Church-Turing Thesis (1936) Theory Hall of Fame. Theory Hall of Fame. Undecidability The Turing Machine Computability Motivating idea Build a theoretical a human computer Likened to a human with a paper and pencil that can solve problems in an algorithmic way The theoretical provides a

More information

Problems, and How Computer Scientists Solve Them Manas Thakur

Problems, and How Computer Scientists Solve Them Manas Thakur Problems, and How Computer Scientists Solve Them PACE Lab, IIT Madras Content Credits Introduction to Automata Theory, Languages, and Computation, 3rd edition. Hopcroft et al. Introduction to the Theory

More information

CSE 2001: Introduction to Theory of Computation Fall Suprakash Datta

CSE 2001: Introduction to Theory of Computation Fall Suprakash Datta CSE 2001: Introduction to Theory of Computation Fall 2013 Suprakash Datta datta@cse.yorku.ca Office: CSEB 3043 Phone: 416-736-2100 ext 77875 Course page: http://www.cse.yorku.ca/course/2001 11/7/2013 CSE

More information

NP-Completeness. Subhash Suri. May 15, 2018

NP-Completeness. Subhash Suri. May 15, 2018 NP-Completeness Subhash Suri May 15, 2018 1 Computational Intractability The classical reference for this topic is the book Computers and Intractability: A guide to the theory of NP-Completeness by Michael

More information

Computability and Complexity

Computability and Complexity Computability and Complexity Lecture 5 Reductions Undecidable problems from language theory Linear bounded automata given by Jiri Srba Lecture 5 Computability and Complexity 1/14 Reduction Informal Definition

More information

CSCI3390-Lecture 16: NP-completeness

CSCI3390-Lecture 16: NP-completeness CSCI3390-Lecture 16: NP-completeness 1 Summary We recall the notion of polynomial-time reducibility. This is just like the reducibility we studied earlier, except that we require that the function mapping

More information

Lecture 25: Cook s Theorem (1997) Steven Skiena. skiena

Lecture 25: Cook s Theorem (1997) Steven Skiena.   skiena Lecture 25: Cook s Theorem (1997) Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Prove that Hamiltonian Path is NP

More information

DRAFT. Algebraic computation models. Chapter 14

DRAFT. Algebraic computation models. Chapter 14 Chapter 14 Algebraic computation models Somewhat rough We think of numerical algorithms root-finding, gaussian elimination etc. as operating over R or C, even though the underlying representation of the

More information

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem. 1 More on NP In this set of lecture notes, we examine the class NP in more detail. We give a characterization of NP which justifies the guess and verify paradigm, and study the complexity of solving search

More information

Chapter 7 Turing Machines

Chapter 7 Turing Machines Chapter 7 Turing Machines Copyright 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 A General Model of Computation Both finite automata and pushdown automata are

More information