Lecture 3: Nondeterministic Finite Automata

Similar documents
Closure under the Regular Operations

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Nondeterministic Finite Automata

Theory of Computation (I) Yijia Chen Fudan University

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

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

Inf2A: Converting from NFAs to DFAs and Closure Properties

Non-deterministic Finite Automata (NFAs)

Lecture 1: Finite State Automaton

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Finite Automata and Regular languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Constructions on Finite Automata

Chapter Five: Nondeterministic 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,

September 7, Formal Definition of a Nondeterministic Finite Automaton

CS243, Logic and Computation Nondeterministic finite automata

Equivalence of DFAs and NFAs

CS 455/555: Finite automata

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

Constructions on Finite Automata

Nondeterministic finite automata

Nondeterministic Finite Automata

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

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

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

Intro to Theory of Computation

Automata and Languages

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

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

Chapter 6: NFA Applications

CS 121, Section 2. Week of September 16, 2013

Chap. 1.2 NonDeterministic Finite Automata (NFA)

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

CS21 Decidability and Tractability

Deterministic Finite Automaton (DFA)

CS 154, Lecture 3: DFA NFA, Regular Expressions

Finite Automata Part Two

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

Computational Models Lecture 2 1

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

Computational Models Lecture 2 1

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

Theory of Computation (II) Yijia Chen Fudan University

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Nondeterministic Finite Automata

UNIT-III REGULAR LANGUAGES

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

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

Theory of Languages and Automata

CSC236 Week 11. Larry Zhang

Equivalence of Regular Expressions and FSMs

Finite Automata Part Two

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

Java II Finite Automata I

CSE 105 THEORY OF COMPUTATION

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Fooling Sets and. Lecture 5

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

CPS 220 Theory of Computation REGULAR LANGUAGES

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

Nondeterminism. September 7, Nondeterminism

Regular Expressions. Definitions Equivalence to Finite Automata

Chapter 2: Finite Automata

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Further discussion of Turing machines

Automata: a short introduction

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Uses of finite automata

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

Decision, Computation and Language

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

CS21 Decidability and Tractability

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

DM17. Beregnelighed. Jacob Aae Mikkelsen

Takeaway Notes: Finite State Automata

Theory of Computation

Sri vidya college of engineering and technology

2017/08/29 Chapter 1.2 in Sipser Ø Announcement:

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

Finite Automata. Finite Automata

Computational Models - Lecture 1 1

Closure under the Regular Operations

Course 4 Finite Automata/Finite State Machines

Non-Deterministic Finite Automata

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

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

Lecture 4 Nondeterministic Finite Accepters

Classes and conversions

Finite Automata and Regular Languages (part III)

Finite Automata. Seungjin Choi

CS 154 Introduction to Automata and Complexity Theory

Lecture 17: Language Recognition

C2.1 Regular Grammars

Extended transition function of a DFA

Transcription:

Lecture 3: Nondeterministic Finite Automata September 5, 206 CS 00 Theory of Computation As a recap of last lecture, recall that a deterministic finite automaton (DFA) consists of (Q, Σ, δ, q 0, F ) where Q is a finite set of states, Σ is a finite alphabet, δ : Q Σ Q is the transition function, q 0 Q is the start state, and F Q is the set of accepting states. We also defined a computation history (CH) of a DFA M on input w = w... w n as a sequence r 0, r,..., r n such that () r 0 = q 0 of M and (2) for i n, r i = δ(r i, w i ) where δ is M s transition function. M accepts w if the CH ends in r n F ; we also say that the language of M L(M) = {w M accepts w}. Topics Covered. Regular Operations 2. Nondeterministic Finite Automata 3. Equivalence of NFAs and DFAs Regular Operations Let A and B be regular languages. The following three operations are regular operations: The union of A and B is C = A B = {w w or w B} The concatenation is C = A B = {w w = x y such that x A, y B} The Kleene star of A is A = {w w = x... x k such that k 0 and for all 0 i k, x i A The Closure Theorem Regular languages are closed under union, concatenation, and Kleene star. That is, if A and B are regular languages, then so are A B, A B, A, and B. Last time, we saw a proof idea for proving closure under union. What about concatenation? Here is what we wish to show: Let M A be a DFA that recognizes language A, and let M B be a DFA that recognizes language B. Then we can construct a DFA for C = A B. Lecture 3: Nondeterministic Finite Automata Page / 7

For our first idea, we might try jumping between M A and M B, so we read the first part of the input in M A, reach an accept state, and then jump to the start state in M B. The problem with this is that jumping from an accept state of M A to a start state of M B requires consuming one of the characters of the input string. Alternatively, what if we take all transitions to accept states of M A, and instead make them go directly to the start state of M B? This is also problematic. For example, consider the languages A = {w w consists of one or more 0s only} and B = {w w consists of one or more s only}. If we replace transitions to the accept state of M A with transitions to the start state of M B we get the following automaton M C : 0 (added) 0 (deleted) b 0 b a 0 0 0 0, 0, The language L(M C ) = {w w has one 0, followed by one or more s}. This machine would not accept the string 00, which is in A B. For another idea, we might relax the notion of a finite automaton to allow for empty transitions. This is helpful because we can add empty transitions from the accept states of M A to the start state of M B. Then we can jump between the machines without reading one of the input characters. With this addition, the automaton M C from the previous example would become: Lecture 3: Nondeterministic Finite Automata Page 2 / 7

0 b 0 b a 0 0 0 0, 0, Note that this new machine M C does accept 00. At state a, you can either read in a 0 and stay at a, or you can jump to b 0 without reading any new characters of the input string. If there exists some choice that leads to an accepting state, then we consider a string to be accepted. This leads us to the definition of a nondeterministic finite automaton. 2 Nondeterministic Finite Automata A nondeterministic finite automaton (NFA) consists of (Q, Σ, δ, q 0, F ) where:. Q is a finite set of states 2. Σ is a finite alphabet 3. δ : Q (Σ {}) P(Q). For brevity of notation, we use Σ to denote Σ {}. The term P(Q) = {S S Q} refers to the powerset of Q. This means that a state and input symbol can transition to some subset of the states of Q, rather than only a single state of Q. 4. q 0 is a start state 5. F Q Note that there are many similarities between the definitions of a DFA and NFA. While a DFA acts deterministically in response to a specific state and input symbol, an NFA may behave in one of many ways nondeterministically. Nonetheless, there are other parallels between DFAs and NFAs, such as the notion of a computation history. A computation history (CH) of an NFA N on input w consists of w w m and r 0, r,..., r m such that: Lecture 3: Nondeterministic Finite Automata Page 3 / 7

. w i Σ for all i and w = w... w m 2. r 0 = q 0 3. for all i m, r i δ(r i, w i ) For an example of an NFA, recall the language A = {anna} from the previous class. This is a regular language, as we can build a DFA to recognize A. We can also build a machine to recognize B = {w w contains anna}. Note that a string such as aannaa is in B but not in A. Consider the following NFA, which recognizes B: a, n a, n a n n a This NFA doesn t need a doom state (usually indicated in these notes with a sadface). In an NFA, it s possible for a computation to simply become stuck and have no possible moves out of its current state. In this case, it will never reach an accept state. As another example, let the language C = {w w 3, and w has a somewhere in the last three positions}. An NFA for C looks like: 0, 0,, 0,, q 0 q q 2 q 3 3 Equivalence of DFAs and NFAs Theorem Corollary Let N be an NFA. Then there exists a DFA M such that L(M) = L(N). The language L(N) is regular if N is an NFA. Let s consider as an example the NFA for the language C, pictured above, to see how we might determine the strings that are accepted by an NFA. In this case, suppose the NFA runs on input 00. We can determine the possible states at each time step; given previous time steps, we then consider all possibilities for the next step. For this input, the possible states at each time step are:. Time 0: {q 0 } Lecture 3: Nondeterministic Finite Automata Page 4 / 7

2. Time : {q 0 } 3. Time 2: {q 0, q, q 2, q 3 } 4. Time 3: {q 0, q, q 2, q 3 } 5. Time 4: {q 0, q 2, q 3 } Observe that at Time 4, when the NFA is done reading the input string, an accept state q 3 is included in the set of possible states. This means that there exists an accepting computation history for 00, so it is in the language of the NFA. Construction of an Equivalent DFA Suppose we have an NFA N = (Q N, Σ, δ N, q 0N, F N ) and would like to construct a DFA M = (Q M, Σ, δ M, q 0M, F M ) that recognizes the same language. We can construct M with the following components:. Q M = P(Q N ). In other words, the states of M are sets of states in Q N. 2. Σ remains the same 3. δ M (q, a) = {the set of states of N that are reachable from any state in the subset q Q M Q N when reading a Σ} 4. q 0M = {the set of all states reachable from q 0N by empty transitions} 5. F M = {q q F N } Is the start state of an NFA the same as the start state in the equivalent DFA? Not necessarily; as a counterexample, consider the following NFA N: r a r 3 r 2 a r 4 r5 Here is Anna s Anna Lysys. The start state of N is r. However, the start state of an equivalent DFA M is the set of all states in N reachable from r by an empty transition. This set includes r and r 3. Thus, the start state of M is the state {r, r 3 }. Lecture 3: Nondeterministic Finite Automata Page 5 / 7

The Closure Theorem Regular languages are closed under union, concatenation, and Kleene star. That is, if A and B are regular languages, then so are A B, A B, A, and B. While we could prove this by constructing DFAs for the union, concatenation, and Kleene star of regular languages, we saw that we ran into some problems when trying to do this for concatenation. In particular, we introduced the notion of empty transitions to construct an automaton that recognized the concatenation of two regular languages. It turns out that we can instead construct NFAs to recognize these languages. Because any NFA has an equivalent DFA, a language recognized by an NFA is regular. Proof Idea for Union To build an NFA to recognize A B for regular languages A and B, we can construct components:. Q = {q 0 } Q A Q B 2. Σ remains the same 3. δ(q, a) = {δ A (q, a)} if q Q A and a Σ, or {δ B (q, a)} if q Q B and a Σ. We also add two transitions δ(q 0, ) = {q 0A } and δ(q 0, ) = {q 0B }. 4. q 0 is the new start state 5. F = F A F B q 0 b 0 a b a b 2 Lecture 3: Nondeterministic Finite Automata Page 6 / 7

Proof Idea for Concatenation components: To construct an NFA recognizing A B, we use the. Q = Q A Q B 2. Σ remains the same 3. δ(q, a) = {δ A (q, a)} if q Q A and a Σ, or {δ B (q, a)} if q Q B and a Σ. We also add empty transitions between every accept state in A to q 0B. That is, δ(q, ) = {q 0B } for every q F A. 4. q 0 = q 0A 5. F = F B b a b 0 a b 2 Proof Idea for Kleene Star Given a regular language A, we can construct an NFA for A with empty transitions from all accept states to a new start state q 0. We also add an empty transition from this new start state, which is also an accept state, to the old start state. This accounts for the fact that A. Lecture 3: Nondeterministic Finite Automata Page 7 / 7