Automata and Formal Languages - CM81 Non-Deterministic Finite Automata Andrés Sicard-Ramírez Universidad EAFIT Semester 217-2
Non-Deterministic Finite Automata (NFA) Introduction q i a a q j a q k The automaton can be in several states at once Facilitates the design of automata Question: Are the NFAs more powerful than the DFAs? Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 2/38
Non-Deterministic Finite Automata (NFA) Example (A NFA accepting all the binary strings that end in 1), 1 q start q 1 1 q 2 q : The automaton guess that the final 1 has not begun. q 1 : The automaton guess that the final 1 has begun. q 2 : The word ends in 1. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 3/38
NFA Definition Definition (NFA) A NFA is a quintuple (Q, Σ, δ, q, F ) where Q: A finite set of states Σ: An alphabet of input symbols δ Q Σ P(Q): A transition function q Q: A start state F Q: A set of accepting (or final) states Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 4/38
Extension of the Transition Function for NFAs Let N = (Q, Σ, δ, q, F ) be a NFA. The function δ Q Σ P(Q) δ(q, ε) = {q}, δ(q, xa) = p δ(q,x) δ(p, a). δ is recursively defined by Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 5/38
Language Accepted by a NFA Definition (Language accepted by a NFA) Let D = (Q, Σ, δ, q, F ) be a DFA. The language accepted by D is L(D) = {w Σ δ(q, w) F }. Hopcroft, J. E., Motwani, R. and Ullman, J. D. (27). Introduction to Automata theory, Languages, and Computation, 2.4. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 6/38
Language Accepted by a NFA Definition (Language accepted by a NFA) Let D = (Q, Σ, δ, q, F ) be a DFA. The language accepted by D is L(D) = {w Σ δ(q, w) F }. Let N = (Q, Σ, δ, q, F ) be a NFA. The language accepted by N is L(N) = {w Σ δ(q, w) F }. Hopcroft, J. E., Motwani, R. and Ullman, J. D. (27). Introduction to Automata theory, Languages, and Computation, 2.4. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 7/38
Language Accepted by a NFA Definition (Language accepted by a NFA) Let D = (Q, Σ, δ, q, F ) be a DFA. The language accepted by D is L(D) = {w Σ δ(q, w) F }. Let N = (Q, Σ, δ, q, F ) be a NFA. The language accepted by N is Reading L(N) = {w Σ An application: Text search. δ(q, w) F }. Hopcroft, J. E., Motwani, R. and Ullman, J. D. (27). Introduction to Automata theory, Languages, and Computation, 2.4. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 8/38
Language Accepted by a NFA Theorem (Hopcroft, Motwani and Ullman [27], Example 2.9) For the NFA of the figure, L(N) = {w {, 1} w ends in 1}., 1 q start q 1 1 q 2 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 9/38
Language Accepted by a NFA Theorem (Hopcroft, Motwani and Ullman [27], Example 2.9) For the NFA of the figure, L(N) = {w {, 1} w ends in 1}., 1 q start q 1 1 q 2 Sketch of proof Mutual induction on the following propositions: S (w): q δ(q, w) for all w Σ S 1 (w): q 1 δ(q, w) w ends in S 2 (w): q 2 δ(q, w) w ends in 1 From S 2 (w) and F = {q 2 } then the theorem follows. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 1/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.3.4.a) NFA accepting the set of strings over Σ = {1, 2, 3} such that the final digit has appeared before. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 11/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.3.4.a) NFA accepting the set of strings over Σ = {1, 2, 3} such that the final digit has appeared before. Σ {1} q 1 Σ i start 1 2 3 Σ {2} 1 q 2 Σ {3} 3 2 f q i : The automaton guess that the repeated digit is i. q 3 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 12/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.3.4.b) NFA accepting the set of strings over Σ = {, 1, 2} such that the final digit has not appeared before. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 13/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.3.4.b) NFA accepting the set of strings over Σ = {, 1, 2} such that the final digit has not appeared before. Σ start Σ {} q i Σ {} q q f Σ {1} Σ {1} 1 Σ {2} q 1 Σ {2} 2 q 2 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 14/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.3.4.c) NFA accepting the set of strings over Σ = {, 1} such that there are two s separated by a number of positions that is multiple of 2. Note that is an allowable multiple of 2. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 15/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.3.4.c) NFA accepting the set of strings over Σ = {, 1} such that there are two s separated by a number of positions that is multiple of 2. Note that is an allowable multiple of 2. Σ q Σ q 1 q 2 start 1 Σ q Σ 3 q Σ 4 q 5 q 6 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 16/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.5.3.b) NFA accepting the set of strings that consist of either 1 repeated one or more times or 1 repeated one or more times. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 17/38
Language Accepted by a NFA Example (Hopcroft, Motwani and Ullman [27], Exercise 2.5.3.b) NFA accepting the set of strings that consist of either 1 repeated one or more times or 1 repeated one or more times. q q 1 1 q 2 start q 1 3 q 4 q 5 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 18/38
The Subset Construction Input: A NFA N = (Q N, Σ, δ N, q, F N ) Output: A DFA D = (Q D, Σ, δ D, {q }, F D ) where Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 19/38
The Subset Construction Input: A NFA N = (Q N, Σ, δ N, q, F N ) Output: A DFA D = (Q D, Σ, δ D, {q }, F D ) where Q D = P(Q N ), F D = {S P(Q N ) S F N }, δ D (S, a) = δ N (p, a), for each S P(Q N ) and a Σ. p S Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 2/38
The Subset Construction Example Given the following NFA to build the DFA given by the subset construction., 1 q start q 1 1 q 2 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 21/38
The Subset Construction Example (cont.) {q, q 1, q 2 } {q 1, q 2 } {q 1 } {q 2 } {q } {q, q 1 } {q, q 2 } start
The Subset Construction Example (cont.), 1 {q, q 1, q 2 } {q 1, q 2 } 1 1, 1 1 1 {q 1 } {q 2 } {q } 1 {q, q 1 } {q, q 2 } start 1 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 23/38
The Subset Construction Example (cont.) 1 1 start {q } {q, q 1 } {q, q 2 } 1 Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 24/38
Equivalence of DFAs and NFAs Example (Special case) A NFA recognising the word then : t h e n start q t th the then Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 25/38
Equivalence of DFAs and NFAs Example (Special case) A NFA recognising the word then : t h e n start q t th the then The DFA given by the subset construction: t h e n start {q } {t} {th} {the} {then} Σ {t} Σ {h} Σ {e} Σ {n} Σ Σ Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 26/38
Equivalence of DFAs and NFAs Let D = (Q D, Σ, δ D, {q }, F D ) be the DFA constructed from a NFA N = (Q N, Σ, δ N, q, F N ) by the subset construction. Theorem (Proof by structural induction on w) δ D ({q }, w) = δ N (q, w). Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 27/38
Equivalence of DFAs and NFAs Let D = (Q D, Σ, δ D, {q }, F D ) be the DFA constructed from a NFA N = (Q N, Σ, δ N, q, F N ) by the subset construction. Theorem (Proof by structural induction on w) δ D ({q }, w) = δ N (q, w). Theorem (Hopcroft, Motwani and Ullman [27], Theorem 2.11) L(D) = L(N). Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 28/38
Equivalence of DFAs and NFAs Theorem (Hopcroft, Motwani and Ullman [27], Exercise 2.3.5) Let D = (Q, Σ, δ D, q, F ) be a DFA and let N = (Q, Σ, δ N, q, F ) be a NFA, where δ N is defined by: Hence, if if δ D (q, a) = p, then δ N (q, a) = {p}. (1) δ D (q, w) = p, then δ N (q, w) = {p}. (Proof in the next slides) Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 29/38
Equivalence of DFAs and NFAs Proof (by structural induction on w) 1. P (w): If δ D (q, w) = p, then δ N (q, w) = {p}. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 3/38
Equivalence of DFAs and NFAs Proof (by structural induction on w) 1. P (w): If δ D (q, w) = p, then δ N (q, w) = {p}. 2. Basis step P (ε): Since δ D (q, ε) = q (by def. of of δ N ) then P (ε). δ D ) and δ N (q, ε) = {q } (by def. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 31/38
Equivalence of DFAs and NFAs Proof (cont.) 3. Inductive step: x Σ. a Σ. P (x) P (xa) Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 32/38
Equivalence of DFAs and NFAs Proof (cont.) 3. Inductive step: x Σ. a Σ. P (x) P (xa) Inductive hypothesis P (x): If δ D (q, x) = p, then δ N (q, x) = {p}. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 33/38
Equivalence of DFAs and NFAs Proof (cont.) 3. Inductive step: x Σ. a Σ. P (x) P (xa) Inductive hypothesis P (x): If Let δ D (q, x) = p, then δ N (q, x) = {p}. δ D (q, x) = p and δ D (p, a) = q, that is, δ D (q, xa) = q. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 34/38
Equivalence of DFAs and NFAs Proof (cont.) 3. Inductive step: x Σ. a Σ. P (x) P (xa) Inductive hypothesis P (x): If Let Hence δ D (q, x) = p, then δ N (q, x) = {p}. δ D (q, x) = p and δ D (p, a) = q, that is, δ D (q, xa) = q. Therefore, if δ N (q, xa) = p δ N (q,x) = p {p} δ N (p, a) δ N (p, a) (by def. of δ N ) (by IH) = {q} (by (1)) δ D (q, xa) = q, then δ N (q, xa) = {q}. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 35/38
Equivalence of DFAs and NFAs Theorem (Hopcroft, Motwani and Ullman [27], Theorem 2.12) A language L is accepted by some DFA if and only if L is accepted by some NFA. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 36/38
Equivalence of DFAs and NFAs Theorem (Hopcroft, Motwani and Ullman [27], Theorem 2.12) A language L is accepted by some DFA if and only if L is accepted by some NFA. Definition (Regular language) A language L is regular if exists a finite automaton A (DFA or NFA) such L = L(A). Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 37/38
References Hopcroft, J. E., Motwani, R. and Ullman, J. D. (27). Introduction to Automata theory, Languages, and Computation. 3rd ed. Pearson Education. Automata and Formal Languages - CM81. Non-Deterministic Finite Automata 38/38