CS243, Logic and Computation Nondeterministic finite automata

Similar documents
COM364 Automata Theory Lecture Note 2 - Nondeterminism

CS 455/555: Finite automata

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,

Lecture 3: Nondeterministic Finite Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Nondeterministic Finite Automata

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

CS 154, Lecture 3: DFA NFA, Regular Expressions

Finite Automata and Regular languages

September 7, Formal Definition of a Nondeterministic Finite Automaton

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

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

Nondeterministic finite automata

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Theory of Computation (I) Yijia Chen Fudan University

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Nondeterministic Finite Automata

Sri vidya college of engineering and technology

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Non-deterministic Finite Automata (NFAs)

Chapter Five: Nondeterministic Finite Automata

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

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

Closure under the Regular Operations

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Inf2A: Converting from NFAs to DFAs and Closure Properties

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

CPSC 421: Tutorial #1

Theory of Languages and Automata

Fooling Sets and. Lecture 5

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

Computer Sciences Department

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

Further discussion of Turing machines

Theory of Computation

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Nondeterminism. September 7, Nondeterminism

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

Uses of finite automata

(Refer Slide Time: 0:21)

CSC173 Workshop: 13 Sept. Notes

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Automata and Languages

Intro to Theory of Computation

Theory of Computation Lecture 1. Dr. Nahla Belal

DM17. Beregnelighed. Jacob Aae Mikkelsen

Lecture 1: Finite State Automaton

V Honors Theory of Computation

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Nondeterministic Finite Automata

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

CHAPTER 1 Regular Languages. Contents

CSE 105 THEORY OF COMPUTATION

Theory of computation: initial remarks (Chapter 11)

Computational Theory

CSCE 551 Final Exam, Spring 2004 Answer Key

Lecture 23 : Nondeterministic Finite Automata DRAFT Connection between Regular Expressions and Finite Automata

Chap. 1.2 NonDeterministic Finite Automata (NFA)

CS21 Decidability and Tractability

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Chapter 2: Finite Automata

UNIT-III REGULAR LANGUAGES

Decision, Computation and Language

Lecture 17: Language Recognition

Theory of Computation (II) Yijia Chen Fudan University

Chapter 6: NFA Applications

arxiv: v2 [cs.fl] 29 Nov 2013

Finite Automata. Seungjin Choi

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Proving languages to be nonregular

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

CPS 220 Theory of Computation REGULAR LANGUAGES

Finite Automata and Regular Languages (part III)

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Languages, regular languages, finite automata

Final exam study sheet for CS3719 Turing machines and decidability.

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

Deterministic Finite Automata (DFAs)

Regular Languages. Problem Characterize those Languages recognized by Finite Automata.

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

NOTES ON AUTOMATA. Date: April 29,

Theory of Computation (IV) Yijia Chen Fudan University

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Equivalence of DFAs and NFAs

Introduction to the Theory of Computing

Finite Automata (contd)

Regular Languages. Kleene Theorem I. Proving Kleene Theorem. Kleene Theorem. Proving Kleene Theorem. Proving Kleene Theorem

Deterministic Finite Automata (DFAs)

Deterministic Finite Automaton (DFA)

Algorithms for NLP

CS 154 Introduction to Automata and Complexity Theory

Non-Deterministic Finite Automata

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

Lecture 4: Finite Automata

CSE 105 Theory of Computation Professor Jeanne Ferrante

Transcription:

CS243, Prof. Alvarez NONDETERMINISTIC FINITE AUTOMATA (NFA) Prof. Sergio A. Alvarez http://www.cs.bc.edu/ alvarez/ Maloney Hall, room 569 alvarez@cs.bc.edu Computer Science Department voice: (67) 552-4333 Boston College fax: (67) 552-679 Chestnut Hill, MA 2467 USA CS243, Logic and Computation Nondeterministic finite automata We will discuss a theoretical tool that is useful for reasoning about computation in DFA. Nondeterministic finite automata (NFA) The computation of a DFA on a given input string is uniuely determined: given a DFA M, and an input string w over the input alphabet of M, the computation of M on input w is the uniue seuence of states defined by recursion in the notes on DFA. There are variants of DFA that allow multiple computations on a given input string. Some of these are probabilistic, in the sense that the present state and input symbol only determine the probability distribution of the next state. For example, when the probabilistic FA is in state 2 reading a at the input, the next state might be with probability 2/3, and 3 with probability /3. However, the variant that we will focus on here, the Non-deterministic Finite Automaton (NFA), is one that may seem more mysterious at first: in contrast with a probabilistic FA, an NFA is able to choose among several future states when in a given state reading a given input symbol. The choice among these options is entirely arbitrary; it need not satisfy any statistical constraints such as having a particular distribution. We will see that NFA are useful as a theoretical device. They are less appealing from a practical point of view, as no efficient implementations of NFA are currently available.. Definition of NFA An NFA is a tuple N = (Q, Σ, δ,, F ) of objects that are similar to those in DFA, with one big difference: in an NFA, the transition function is a map δ : Q (Σ {}) P(Q), where P(Q) is the set of all subsets of the state space Q. What this means is that, if N is in state and ready to read input symbol a, then one of the following can occur:. N may read a and change state to any state in the set δ(, a) if δ(, a) is nonempty. 2. N may change to any state in δ(, ) without reading any input, if δ(, ) is nonempty. 3. N s computation will end prematurely if δ(, x) is empty for all x Σ {}. Example.. The NFA in Fig. accepts all binary strings that end in : given an input string, the NFA chooses to loop at the start state until just before the final, if there is one, and only then jumps to the accepting state.

CS243, Prof. Alvarez NONDETERMINISTIC FINITE AUTOMATA (NFA), start Figure : NFA that accepts all binary strings that end in..2 Formal definition of non-deterministic finite automaton (NFA) A non-deterministic finite automaton (NFA) is a tuple N = (Q, Σ, δ,, F ), where: Q is a finite set known as the state space Σ is a finite set of symbols known as the input alphabet δ : Q (Σ {}) P(Q) is the state transition function, where P(S), for any set S, denotes the set of all subsets of S is an element of Q known as the start state F is a subset of Q known as the set of accepting (or final) states.3 Computation in an NFA An input string w of length n drives an NFA N along a state trajectory r, r,, r m in the state space. However, in contrast with the case of DFA, for an NFA the trajectory is not always uniuely determined by the input string. Furthermore, state trajectories may end prematurely (m < n) or include a greater number of state transitions than there are symbols in the input string (m > n). This is why the term non-deterministic is used in the name of NFA. A seuence r, r m in the state space Q is an allowed state trajectory if there is a driving string w of length m obtained by inserting zero or more symbols (in arbitrary locations) to some prefix string of the input string w, such that the state seuence r k is consistent with the transition function of N as described below.. r = 2. r k δ(r k, w k ) for each k with < k m A computation succeeds if it reads the entire input string. A computation fails if it ends prematurely because there are no valid next states for the last state in the computation and the current input at that time. Example.2. The following are valid state trajectories of the NFA in Fig. on input., (fails),, (fails),,, (succeeds)

CS243, Prof. Alvarez NONDETERMINISTIC FINITE AUTOMATA (NFA).4 Language recognized by an NFA An NFA N accepts a string w over the input alphabet of N if, and only if, there is a computation of N on input w that succeeds in processing all of w and ends in an accepting state of N. The language L(N) recognized by N is the set of all strings that are accepted by N. Example.3. The NFA in Fig. recognizes the language of binary strings that end in. Example.4. An NFA that recognizes the set of strings over {,, 2} that contain the substring 2 is shown in Fig. 2.,, 2,, 2 start 2 2 f Figure 2: NFA that accepts all binary strings that contain the substring 2. Example.5. Fig. 3 shows an NFA that accepts all binary strings that do not contain as a substring. Computation begins in the start state. After an initial segment of zero or more s at the input, the machine transitions to the accepting state, where any s can be processed. The transition allows the transition to occur without reading any input. This is used here, in particular, so that the empty string will be accepted. start Figure 3: NFA that accepts all binary strings that do not contain as a substring..5 Closure of NFA-recognizable languages under concatenation The constructions discussed in the notes on DFA also show that the set of languages that are recognized by some NFA is closed under complements and unions. There is an additional closure property that is easy to prove in the case of NFA. Theorem.. Suppose that N and N 2 are NFA over the same input alphabet Σ. There is an NFA, M, that recognizes the language L(N )L(N 2 ) = {v w v L(N ), w L(N 2 )} that contains the concatenations of a string of L(N ) followed by a string of L(N 2 ).

CS243, Prof. Alvarez NONDETERMINISTIC FINITE AUTOMATA (NFA) Proof. We can essentially concatenate the machines N and N 2. Begin by noticing that no generality is lost if we assume that N has a single accepting state. This is because if several accepting states are designated, then we can add to N a new state f, together with transitions from all accepting states of N to f, and then make f the sole accepting state of the updated machine N. We construct an NFA N from N and N 2 as follows. Assume that N i = (Q i, Σ, δ i,,i, F i ) for i =, 2, and that N has a single accepting state (see comment above). Let Q = Q Q 2, assuming that Q and Q 2 to be disjoint sets (formally, if this reuirement is not satisfied, we can take the union of Q {} and Q 2 {2} instead). We leave all transitions of both N and N 2 intact, and we add a new transition from the accepting state of N to the start state of N 2. We then take the set F of accepting states of the new machine N to be the set F 2 of the set of accepting states of N 2. It is clear from the construction that a string w will be accepted by N if, and only if, w = uv where u drives N from its start state to its accepting state, and v drives N 2 from its start state to one of its accepting states. In other words, the language recognized by L(N) is precisely the concatenation L(N )L(N 2 ), as desired. This completes the proof. Example.6. Fig. 4 shows an NFA that accepts all binary strings of the form uv, where u contains as a substring and v does not contain as a substring. This language illustrates why the concatenation machine construction in the proof of the preceding theorem would not obviously work for DFA: it is not obvious where to split the input string and jump from one machine to the other. For example, consider the string w =. Scanning w from left to right, there is a first point at which has been read (and where the accepting state of N has first been reached), corresponding to splitting w into followed by. However, if a jump to the start state of N 2 were made when the accepting state of N is first reached, then the subseuent computation in N 2 would not accept the input, since the remaining string contains the prohibited substring. Nondeterminism, in the form of transitions, allows the jump to made at an appropriate point during the computation. In this example, this would correspond to splitting w into and., start 2 3 4 Figure 4: NFA that accepts strings uv, where u contains and v does not contain.

CS243, Prof. Alvarez 2 EQUIVALENCE OF NFA AND DFA 2 Euivalence of NFA and DFA On the surface, it appears that NFA are computationally more powerful than DFA. For example, we saw above that the concatenation of two NFA-recognizable languages is also NFA-recognizable. We did this by way of the concatenation of two NFA, a construction that presents difficulties in the case of DFA. We saw in an example that it is not clear how a DFA would decide to jump from one machine to another in attempting to split a string into a suitable concatenation of strings in the languages under consideration. Despite these concerns, it turns out that every NFA-recognizable language is also DFArecognizable! In particular, the class of DFA-recognizable languages is closed under concatenation. We will prove this by showing that any NFA may be simulated by a suitable DFA that has as its state space the set of all subsets of the state space of N. Theorem 2.. Suppose that N = (Q, Σ, δ,, F ) is an NFA. There exists a DFA M = (P(Q), Σ, δ M,,M, F M ) such that L(M) = L(N). Proof. The intuition behind the construction is that, since a computation of N on a given input string can branch because of nondeterminism, we can keep track of the possibilities by listing all possible states that can occur after reading a certain number of input symbols. Thus, a single set of states can represent the various possible states of N at that point in time. Accordingly, we take the state space of the DFA M to be P(Q), the set of all subsets of the state space of the NFA N. A natural candidate to serve as the start state of M is the set { } that contains only the start state of N. However, if there are transitions leaving, then it is possible for a computation in N to leave before any input symbols have been processed. Therefore, we will take as the start state of M the -closure of { }, defined as the set of all states that can be reached from by following zero or more transitions in N. Likewise, we take as the set F M of accepting states of M the set of the -closures of the sets { f }, where f F. The transition function of M is defined as follows. S Q a Σ δ M (S, a) = -closure of S δ(, a) This completes the construction of the DFA M that simulates the NFA N. We will now prove that the simulation works as desired.

CS243, Prof. Alvarez 2 EQUIVALENCE OF NFA AND DFA Lemma 2.2. With the above construction of M, there is a computation of N on input w that is in state k after reading the first k symbols of w if, and only if, the final state r k of the uniuely defined computation r,, r k of M on input w, w k contains k. Proof. We prove this claim by induction in k. (Basis) If k = symbols of w have been processed, then only the states in the -closure of { } are reachable in N s computation. By construction, such states are precisely the elements of the start state M of M. This completes the basis of the induction. (Inductive step) Assume that the target statement is true for some non-negative integer, k. Consider a computation of N that has processed w,, w k, w k+. Such a computation consists of a computation of the first k input symbols w,, w k followed by a state transition on input w k+ that is consistent with the transition function δ of N. Specifically, there must exist a state k Q such that N is in state k after processing w, w k in this particular computation of N and (the -closure of) δ( k, w k+ ) contains the final state k+ in the computation of N after reading w k+. Let r, r k+ be the corresponding uniuely defined computation of the DFA M on input w, w k+. By the induction hypothesis, r k contains the state k. Therefore, by definition of M s transition function, it follows that state k+ δ M (r k, w k+ ). Conversely, let r, r k+ be the portion of the uniuely defined computation of M on input w after processing w, w k+. If k+ denotes any state in r k+, then by definition of M s transition function, k+ must be reachable (possibly after transitions) from a state in δ( k, w k+ ) for some state k in r k. By the induction hypothesis, there is a valid computation of N on input w, w k that ends in state k after processing w, w k. It follows that appending k+ produces a valid computation of N on input w, w k+. This completes the inductive step. By Lemma 2.2, if w is any string in Σ, then w L(N) there is a computation of N on input w that ends in some F } the computation of M on input w ends in some S Q M that contains the computation of M on input w ends in some F M, where the last step uses the definition of the set F M of accepting states of M. Therefore, we conclude that L(M) = L(N), as claimed. This completes the proof of Theorem 2.. Example 2.. We carry out the DFA simulation construction for the NFA that appears in Fig.. The state space of the DFA is the set of subsets of {, }, which is the four-element set {, { }, { }, {, }}. The state transition diagram is shown in Fig. 5. Notice that two of the states of the DFA are not reachable from the start state. Thus, the simulating DFA really uses only two states in this case.

CS243, Prof. Alvarez 2 EQUIVALENCE OF NFA AND DFA,, start { } { } {, } Figure 5: DFA simulation construction for NFA in Fig..