Fall, 2017 CIS 262. Automata, Computability and Complexity Jean Gallier Solutions of the Practice Final Exam

Similar documents
THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Theory of Computation

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

Formal Languages, Automata and Models of Computation

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

6.8 The Post Correspondence Problem

1 More finite deterministic automata

Theory Bridge Exam Example Questions

CSCE 551 Final Exam, April 28, 2016 Answer Key

What we have done so far

Chapter 6. Properties of Regular Languages

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

CS 154 Introduction to Automata and Complexity Theory

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Final exam study sheet for CS3719 Turing machines and decidability.

Context-Free Grammars and Languages. Reading: Chapter 5

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008

CPSC 421: Tutorial #1

Computational Models: Class 3

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Sri vidya college of engineering and technology

More Properties of Regular Languages

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Finite and Algorithmic Model Theory II: Automata-Based Methods

Functions on languages:

Finite Automata and Regular Languages

Context-Free Grammars and Languages. We have seen that many languages cannot be regular. Thus we need to consider larger classes of langs.

Computational Models - Lecture 4

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Name: Student ID: Instructions:

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

DD2371 Automata Theory

Mathematical Preliminaries. Sipser pages 1-28

Pushdown Automata. Reading: Chapter 6

Theory of computation: initial remarks (Chapter 11)

Properties of Context-Free Languages

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Context-Free Grammars and Languages

CMPSCI 250: Introduction to Computation. Lecture #32: The Myhill-Nerode Theorem David Mix Barrington 11 April 2014

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CSCE 551: Chin-Tser Huang. University of South Carolina

CMSC 330: Organization of Programming Languages

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

THEORY OF COMPUTATION

Computational Models - Lecture 3

Computational Models - Lecture 3 1

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

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Computational Models - Lecture 5 1

CSE 105 THEORY OF COMPUTATION

Notes on State Minimization

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

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

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

CS 133 : Automata Theory and Computability

CpSc 421 Final Exam December 6, 2008

Computational Models - Lecture 3 1

COL 352 Introduction to Automata and Theory of Computation Major Exam, Sem II , Max 80, Time 2 hr. Name Entry No. Group

3130CIT Theory of Computation

NP-Complete Problems. Complexity Class P. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

Theory of Computation Lecture 1. Dr. Nahla Belal

A Universal Turing Machine

Automata Theory and Formal Grammars: Lecture 1

Languages. Languages. An Example Grammar. Grammars. Suppose we have an alphabet V. Then we can write:

3515ICT: Theory of Computation. Regular languages

Primitive recursive functions: decidability problems

Section 1 (closed-book) Total points 30

Theory of computation: initial remarks (Chapter 11)

This lecture covers Chapter 7 of HMU: Properties of CFLs

Theory of Computation (II) Yijia Chen Fudan University

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

DM17. Beregnelighed. Jacob Aae Mikkelsen

CS154 Final Examination

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

Automata Theory CS F-08 Context-Free Grammars

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Theory of Computation Chapter 9

Ma/CS 117c Handout # 5 P vs. NP

MATH 2200 Final Review

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

CS154 Final Examination

CSE 555 Homework Three Sample Solutions

Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

2 Truth Tables, Equivalences and the Contrapositive

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

Theory of Computation

Decidability (What, stuff is unsolvable?)

The Post Correspondence Problem; Applications to Undecidability Results

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Transcription:

Fall, 2017 CIS 262 Automata, Computability and Complexity Jean Gallier Solutions of the Practice Final Exam December 6, 2017 Problem 1 (10 pts). Let Σ be an alphabet. (1) What is an ambiguous context-free grammar? What is an inherently ambiguous context-free language? (2) Is the following context-free grammar ambiguous, and if so demonstrate why? E E + E E E E E (E) E a. Solution. (1) See Definition 6.5, page 134 of the notes tcbook-u.pdf. (2) Yes, this grammar is ambiguous. For example, the string a + a a has two distinct leftmost derivations and E = E E = E + E E = a + E E = a + a E = a + a a, E = E + E = a + E = a + E E = a + a E = a + a a. Problem 2 (5pts). Given any trim DFA D = (Q, Σ, δ, q 0, F ) accepting a language L = L(D), if D is a minimal DFA, then prove that its Myhill-Nerode equivalence relation D is equal to ρ L. 1

Solution. We proved in Proposition 5.13 (page 99) that for any trim DFA D accepting a language L, we have D ρ L. We also proved that the number of equivalence classes of ρ L is the size of the minimal DFA s for L (again, see page 99). Therefore, if D is a minimal DFA, then D and ρ L have the same number of classes, which implies that D = ρ L. Problem 3 (10 pts). Consider the following DFA D 0 with start state A and final state D given by the following transition table: a b A B A B C A C D A D D A Reverse all the arrows of D 0, obtaining the following NFA N (wihout ɛ-transitions) with start state D and final state A given by the following table: a b A {A, B, C, D} B {A} C {B} D {C, D} This NFA accepts the language {aaa}{a, b}. (1) Use the subset construction to convert N to a DFA D (with 5 states). (2) Prove that D is a minimal DFA. Solution. (1) Applying the subset construction, we obtain the following DFA with start state 0 and final state 4: a b 0 {D} 1 2 1 {C, D} 3 2 2 2 2 3 {B, C, D} 4 2 4 {A, B, C, D} 4 4 2

(2) Let s apply the method for propagating inequivalence described in Section 5.19 of the notes on pages 109-110. Since 4 is the only final state, the intial table is the following (where means inequivalent, and means don t know yet): 1 2 3 4 0 1 2 3 Let us proceed from the botttom up and from right to left (as opposed to the top down). At the end of the first round, we get 1 2 3 4 0 1 2 3 Nothing changes during the second round, so we conclude that there are no pairs of equivalent states, which means that the DFA is minimal. Problem 4 (10 pts). Given any context-free grammar G = (V, Σ, P, S ), with special starting production S S where S only appears in this production, the set of characteristic strings C G is defined by C G = {αβ V S = αbv = αβv, α, β V, v Σ, B β P }. Consider the grammar G with nonteinal set {S, A, C} and teinal set {a, b, c} given by the following productions: S S S AC A aab A ab C c. Describe all rightmost derivations and the set C G. Solution. Rightmost derivations are of the fo S = S 3

or or or S = S = S = S = AC = S AC S AC Ac or S = S S = AC AC = Ac Ac = a n Ab n c a n Ab n c = a n+1 b n+1 c = a n+1 bb n c with n 0. It follows that S = S S = AC AC = Ac Ac = a n Ab n c a n Ab n c = a n+1 Ab n+1 c = a n+1 Abb n c C G = {S, AC, Ac, a n b, a n Ab n 1}. Problem 5 (20 pts). (i) Give a context-free grammar for the language L 2 = {a m b n c p n p, m, n, p 1}. (ii) Prove that the language L 2 is not regular. 4

Solution. Let G 2 be the grammar whose productions are S ABY AY C Y by c bc A aa a B bb b C cc c. It is easy to check (by induction on the length of derivations) that L(G 2 ) = L 2. (ii) We proceed by contradiction using Myhill-Nerode. If L 2 is regular, then there is a right-invariant equivalence relation of finite index such that L 2 is the union of classes of. Consider the infinite sequence ab, ab 2,..., ab n,.... Since has a finite number of classes, there are two distinct strings ab i and ab j in the above sequence such that ab i ab j with 1 i < j. By right-invariance, by concatenating on the right with c i, we obtain ab i c i ab j c i and since i < j, we have ab j c i L 2 and ab i c i / L 2, a contradiction. Problem 6 (10 pts). (i) Give a context-free grammar for the language L 2 = {a m b n n < 3m, m > 0, n 0}. Solution. S asxxx S axx X b ɛ By induction, every leftmost derivation is of the fo with m 0 and n < 3(m + 1). Problem 7 (10 pts). S = m a m SX 3m = a m+1 X 3m+2 = a m+1 b n, lm lm lm 5

Prove that if the language L 1 = {a n b n c n n 1} is not context-free (which is indeed the case), then the language L 2 = {w w {a, b, c}, #(a) = #(b) = #(c)} is not context-free either. Solution. We know from Homework 8 that the context-free languages are closed under intersection with the regular languages. Assume by contradiction that L 2 is context-free. The language R = {a} {b} {c} is regular (for example, an NFA can be easily constructed), and L 1 = L 2 R. Since L 2 is context-free and R is regular, then L 1 is context-free, a contradiction. Problem 8 (10 pts). (1) Prove that the following sets are not computable (ϕ 1, ϕ 2,..., ϕ i,... is an enumeration of the partial computable functions): A = {i N ϕ i = ϕ a ϕ b } B = { i, j, k N ϕ i = ϕ j ϕ k } C = {i N ϕ i (i) = a} where a and b are two fixed natural numbers. (2) Prove that C is listable. Solution. (1) The function ϕ a ϕ b is a partial computable function, say ϕ c, since both ϕ a and ϕ b are partial computable and is partial computable (in fact, primitive recursive). Thus, there is a partial computable function, ϕ i, namely ϕ c, such that ϕ i = ϕ a ϕ b. If ϕ c = ϕ a ϕ b is the partial function undefined everywhere, then the identity function differs from ϕ c and otherwise the partial computable function ϕ c + 1 differs from the partial computable function ϕ a ϕ b. By Rice s Theorem, A is not recursive. Consider the reduction function, f : A B, given by f(i) = i, a, b. The function f is computable (in fact, primitive recursive) and obviously, i A iff f(i) = i, a, b B iff ϕ i = ϕ a ϕ b. Since A is not computable, B is not computable either. The constant function with value a is computable so it appears as ϕ i for some i. Thus i C, and C. On the other hand, the partial computable function undefined everywhere is a partial recursive function, ϕ j, such that j / C. By Rice s Theorem, C is not recursive. 6

(2) Since the function cond is primitive recursive, the set C is listable because it is the domain of the partial computable function (obtained by composition) { 1 if ϕ x (x) = a f(x) = cond(ϕ x (x), a, 1, undefined) = undefined otherwise, where undefined stands for the partial computable function undefined for all inputs. Problem 9 (5 pts). Define the sets K, K 0 and TOTAL. For each one, state whether it is computable, computably enumerable, or not computably enumerable. Solution. If (ϕ i ) i N is the enumeration of the partial computable functions defined in Chapter 8, Section 8.3 of the slides, then K = {x N ϕ x (x) is defined} K 0 = { x, y N ϕ x (y) is defined} TOTAL = {x N ϕ x is defined for all input}. The sets K and K 0 are both computably enumerable but not computable (see Chapter 8). The set TOTAL is not computably enumerable (Lemma 8.10 of the slides). Problem 10 (5 pts). Let f : N N be a total computable function. Prove that if f is a bijection, then its inverse f 1 is also (total) computable. Solution. Since the subtraction operation on natural numbers (monus) is primitive recursive, and since f is computable, the functions g 1, g 2 : N N N given by g 1 (x, y) = f(x) y, g 2 (x, y) = y f(x) are computable. Then the function h: N N defined by minimization by h(y) = min x[abs(f(x), y) = 0] = min x[add(f(x) y, y f(x)) = 0] is partial computable. However, since f is bijective, for any y N, there is a unique x N such that f(x) = y, namely x = f 1 (y), so in fact h = f 1. This shows that f 1 is partial computable, but since it is a total function, it is computable. Problem 11 (10 pts). Recall that the Clique Problem for undirected graphs is this: Given an undirected graph G = (V, E) and an integer K 2, is there a set C of nodes with C K such that for all v i, v j C, there is some edge {v i, v j } E? Equivalently, does G contain a complete subgraph with at least K nodes? 7

Give a polynomial reduction from the Clique Problem for undirected graphs to the Satisfiability Problem. Assuming that the graph G = (V, E) has n nodes and that the budget is an integer K such that 2 K n, create nk boolean variables x ik with intended meaning that x ik = T if node v i is chosen as the kth element of a clique C, with 1 k K, and write clauses asserting that K nodes are chosen to belong to a clique C. Solution. We want to assert that there is an injection κ: {1,..., K} {1,..., n} such that for all h, k with 1 h < k K, there is an edge between v i and v j, with κ(h) = i and κ(k) = j. Since κ(k) = i iff x ik = T, this is equivalent to saying that if x ih = T and x jk = T, then {v i, v j } E. To assert that K choices of nodes are made, equivalently that κ(k) is defined for all k {1,..., K}, write the K clauses (x 1k x 2k x nk ), k = 1,..., K. To assert that at most one node is chosen as the kth node in C, equivalently that κ is a functional relation, write the clauses (x ik x jk ) 1 i < j n, k = 1,..., K. To assert that no node is picked twice, equivalently that κ is injective, write the clauses (x ih x ik ) 1 h < k K, i = 1,..., n. To assert that any two distinct nodes in C are connected by an edge, we say that for all h, k with 1 h < k k, if x ih = T and x jk = T, namely x ih x jk = T, then {v i, v j } E. The contrapositive says that if {v i, v j } / E, then x ih x jk = T, or equivalently (x ih x jk ) = T. Thus we have the clauses (x ih x jk ) if {v i, v j } / E, 1 h < k K, which assert that if there is no edge between v i and v j, then v i and v j should not be chosen to be in C. Let S be the above set of clauses, If the graph G has a clique with at least K nodes, then it has a clique C = {v i1,..., v ik } with K nodes, and then it is clear that the clauses in S are satisfied by the truth assignment v such that { T if j = i k, 1 k K, 1 j n v(x jk ) = F otherwise. Conversely, if the clauses in S are satisfied by a truth assignment v, then we obtain the clique of size K given by C = {v i1,..., v ik } with i k = j iff v(x jk ) = T. Therefore, G has a clique of size at least K iff the set of clauses S is satisfiable. 8