Finite Automata and Regular Languages (part II)

Similar documents
Finite Automata and Regular Languages (part III)

CS 4120 Lecture 3 Automating lexical analysis 29 August 2011 Lecturer: Andrew Myers. 1 DFAs

Languages. A language is a set of strings. String: A sequence of letters. Examples: cat, dog, house, Defined over an alphabet:

Theory of Computation (I) Yijia Chen Fudan University

M = (Q,Σ,δ,q 0,F) Σ is the alphabet over which the transitions are defined.

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Nondeterminism and Epsilon Transitions

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Nondeterministic Finite Automata

Chapter Five: Nondeterministic Finite Automata

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

Nondeterministic Finite Automata

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

Theory of Languages and Automata

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

Computer Sciences Department

1.3 Regular Expressions

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Finite Automata and Regular languages

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Lecture 3: Nondeterministic Finite Automata

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

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

Finite Automata. Finite Automata

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Finite Automata. Seungjin Choi

Theory of Computation (II) Yijia Chen Fudan University

Pseudo-automata for generalized regular expressions

CS243, Logic and Computation Nondeterministic finite automata

Chapter 2: Finite Automata

Introduction to Formal Languages, Automata and Computability p.1/51

Nondeterministic Finite Automata

Automata and Languages

UNIT-III REGULAR LANGUAGES

Computational Theory

Automata, Logic and Games: Theory and Application

CS 455/555: Finite automata

Plan for Today and Beginning Next week (Lexical Analysis)

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Grammars (part II) Prof. Dan A. Simovici UMB

CSE 135: Introduction to Theory of Computation 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,

Reversal of regular languages and state complexity

Inf2A: Converting from NFAs to DFAs and Closure Properties

Chapter 2: Finite Automata

Nondeterministic finite automata

Nondeterministic Finite Automata. Nondeterminism Subset Construction

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

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Lecture 1: Finite State Automaton

Finite Automata. Mahesh Viswanathan

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

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

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

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

September 7, Formal Definition of a Nondeterministic Finite Automaton

Finite Automata and Regular Languages

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

Nondeterminism. September 7, Nondeterminism

C2.1 Regular Grammars

Automata Theory, Computability and Complexity

Lecture 4 Nondeterministic Finite Accepters

C2.1 Regular Grammars

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 43

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

Closure under the Regular Operations

Grammars (part I) Prof. Dan A. Simovici UMB

Chapter 6: NFA Applications

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

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

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

arxiv: v1 [cs.fl] 4 Feb 2013

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

Theory of Computation

(Refer Slide Time: 0:21)

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

What we have done so far

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

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

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Proofs, Strings, and Finite Automata. CS154 Chris Pollett Feb 5, 2007.

Chapter Two: Finite Automata

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

Lecture 2: Regular Expression

Course 4 Finite Automata/Finite State Machines

Classes and conversions

CSC236 Week 10. Larry Zhang

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

Sri vidya college of engineering and technology

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

Computational Models - Lecture 5 1

Theory of computation: initial remarks (Chapter 11)

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

Non Determinism of Finite Automata

CS 420, Spring 2018 Homework 4 Solutions. 1. Use the Pumping Lemma to show that the following languages are not regular: (a) {0 2n 10 n n 0};

Subset construction. We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA. For any NFA A we can build a DFA A D such that L(A) = L(A D )

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Non-deterministic Finite Automata (NFAs)

Transcription:

Finite Automata and Regular Languages (part II) Prof. Dan A. Simovici UMB 1 / 25

Outline 1 Nondeterministic Automata 2 / 25

Definition A nondeterministic finite automaton (ndfa) is a quintuple M = (A, Q, δ, q 0, F ), where A is the input alphaet of M, Q is a finite set of states, δ : Q A P(Q) is the transition function, q 0 Q is the initial state, and F Q is the set of final states of M. We assume A Q =. 3 / 25

Example Consider the ndfa M = ({a, }, {q 0, q 1, q 2, q 2, q 4 }, δ, q 0, {q 1, q 3 }), whose transition function is defined y the tale: State Input q 0 q 1 q 2 q 3 q 4 a {q 1, q 2 } {q 3 } {q 0 } {q 3 } {q 4 } Note the presence of pairs (q, a) such that δ(q, a) =. We refer to such pairs as locking situations of M. For instance, (q 1, a) is a locking situation of M. 4 / 25

Extending the transition function for an ndfa As in the case of the dfa, we can extend the ndfa s transition function δ, defined on single characters, to δ, defined on words. Starting from the transition function δ, we define the function δ : Q A P(Q) as follows: δ (q, λ) = {q} δ (q, xa) = q δ (q,x) δ(q, a) 5 / 25

Graphs of ndfas If M = (A, Q, δ, q 0, F ) is an ndfa, then the graph of M is the marked, directed multigraph G(M), whose set of vertices is the set of states Q. The set of edges of G(M) consists of all pairs (q, q ) such that q δ(q, a) for some a A; an edge (q, q ) is laeled y the input symol a, where q δ(q, a). The initial state q 0 is denoted y an incoming arrow with no source, and the final states are circled. If q δ (q, x), then there is a path in the graph G(M) laeled y x that leads from q to q. 6 / 25

q 1 q 3 a a q 0 a q 2 q 4 7 / 25

Comparing dfas and ndfas In the graph of a dfa M = (A, Q, δ, q 0, F ) you must have exactly one edge emerging from every state q and for every input symol a A. a q 37 c d In the graph of an ndfa M = (A, Q, δ, q 0, F ) you may have states where no arrow emerges, or states where several arrow laeled with the same symol emerge. Also, not every symol needs to appear as a lael of an emerging edge. q No arrow emerges from q a q 7 3 a 8 / 25

Definition The language accepted y the ndfa M = (A, Q, δ, q 0, F ) is L(M) = {x A δ (q 0, x) F }. In other words, x L(M) if there exists a path in the graph of M laeled y x that leads from the initial state into one of the final states. Note that it is not necessary that all paths laeled y x lead to a final state; the existence of one such path suffices to put x into the language L(M). 9 / 25

Example q 1 q 3 a a q 0 a q 2 q 4 Note that a L(M) ecause of the existence of the path (q 0, q 1, q 3 ) laeled y this word and the fact that q 3 is a final state. On the other hand, (q 0, q 2, q 4 ) is another path laeled y x ut q 4 F. 10 / 25

Example (cont d) This ndfa is simple enough to allow an easy identification of all types of words in L(M): 1 The final state q 1 can e reached y applying an aritrary numer of s followed y an a. 2 The final state q 3 can e reached y a path of the form (q 0,..., q 0, q 1, q 3 ), that is y a word of the form k a for k N. 3 The same final state q 3 can e reached via q 2. Input words that allow this transition have the form k aa for k N. Thus, we have L(M) = {} a {} a {} aa = {} {a, a, aa}. 11 / 25

Example Consider an alphaet A = {a 0,..., a n 1 } and a inary relation ρ A A. The language L ρ = {a i0 a ip p N, (a ij, a ij+1 ) ρ for 0 j p 1} is accepted y the ndfa M ρ = (A, Q, δ, q, F ), where Q = {q, q 0,..., q n 1 }, F = {q 0,..., q n 1 }, and δ is given y δ(q, a i ) = {q i } for 0 i n 1; for every i, j such that 0 i, j n 1, δ(q i, a j ) = {q j Q (a i, a j ) ρ}. 12 / 25

Example (cont d) Note that if (a i, a j ) ρ, then (q i, a j ) is a locking situation. The existence of these locking situations is precisely what makes this device a nondeterministic automaton. q 0 a 0. q i a i a j. a j q q j a n 1. q n 1 13 / 25

We show that L ρ = L(M ρ ). Let x = a i0 a ip e a word in L ρ with p 0. We prove y induction on p = x 1 that x L(M ρ ) and that δ (q, x) = {q ip }. The ase case, p = 0, is immediate, since the condition (a ij, a ij+1 ) ρ for 0 j p 1 is vacuous. Suppose that the statement holds for words in L ρ of length at most p and let x = a i0 a ip e a word in L ρ of length p + 1. It is clear that the word y = a i0 a ip 1 elongs to L ρ. By the inductive hypothesis, y L(M ρ ) and δ (q, y) = {q ip 1 }. Since (a ip 1, a ip ) ρ (y the definition of L ρ ), we have δ(q ip 1, a ip ) = {q ip }, so q ip Therefore, x L(M ρ ). q δ(q,y) δ(q, a ip ) = δ (q, ya ip ) = δ (q, x). 14 / 25

To prove the converse inclusion L(M ρ ) L ρ we use an argument y induction on x 1, where x is a word from L(M ρ ), to show that if x = a i0 a ip L(M ρ ), then δ (q, x) = {q ip } and x L ρ. Again, the ase case is immediate. Suppose that the statement holds for words in L(M ρ ) of length less than p + 1 that elong to L ρ, and let x = a i0 a ip e a word in L(M ρ ) of length p + 1. If y = a i0... a ip 1, it is easy to see that y L(M ρ ) ecause no locking situation may arise in M ρ while the symols of y are read. Therefore, y the inductive hypothesis, y L ρ and δ (q, y) = {q ip 1 }. Further, since δ(q ip 1, a ip ), it follows that (a ip 1, a ip ) ρ, so x L ρ, and δ (q, x) = q ip. Thus, L ρ is accepted y the ndfa M ρ. 15 / 25

Let M = (A, Q, δ, q 0, F ) e a nondeterministic automaton, and let : P(Q) A P(Q) e defined y (S, a) = q S δ(q, a) (1) for every S Q and a A. Starting from, we define : P(Q) A P(Q) in the manner used for the transition functions of deterministic automata. Namely, we define for every S Q and a A. (S, λ) = S (2) (S, xa) = ( (S, x), a) (3) 16 / 25

Lemma The functions and defined aove satisfy the following properties: 1 For every family of sets {S 0,..., S n 1 } and every a A, we have: 0 i n 1 S i, a = 2 For every set S Q and x A we have (S, x) = q S 0 i n 1 δ (q, x). (S i, a). 17 / 25

Proof The first part of the lemma is immediate, ecause ( 0 i n 1 S i, a) = {δ(q, a) q 0 i n 1 S i} = 0 i n 1 {δ(q, a) q S i} = 0 i n 1 (S i, a). 18 / 25

The argument for the second part of the lemma is y induction on x. For the asis step, we have x = 0, so x = λ, and (S, λ) = S, q S δ (q, λ) = q S {q} = S. Suppose that the argument holds for words of length n, and let x = za e a word of length n + 1. We have (S, x) = (S, za) = ( (S, z), a) = ( q S δ (q, z), a)(y ind. hyp.) = (δ (q, z), a) q S = δ(r, a) = δ (q, za) = δ (q, x). q S r δ (q,z) q S q S 19 / 25

Nondeterministic automata can e regarded as generalizations of deterministic automata in the following sense. If M = (A, Q, δ, q 0, F ) is a deterministic automaton, consider a nondeterministic automaton M = (A, Q, δ, q 0, F ), where δ (q, a) = {δ(q, a)}. It is easy to verify that for every q Q and x A we have δ (q, x) = {δ (q, x)}. Therefore, L(M ) = {x A δ (q0, x) F } = {x A {δ (q 0, x)} F } = {x A δ (q 0, x) F } = L(M). In other words, for every deterministic finite automaton there exists a nondeterministic one that recognizes the same language. 20 / 25

Theorem For every nondeterministic automaton, there exists a deterministic automaton that accepts the same language. 21 / 25

Proof Let M = (A, Q, δ, q 0, F ) e a nondeterministic automaton. Define the function as in the equality (S, a) = q S δ(q, a), and consider the deterministic automaton M = (A, P(Q),, {q 0 }, {S S Q and S F }). For every x A we have the following equivalent statements: 1 x L(M); 2 δ (q 0, x) F ; 3 ({q 0 }, x) F ; 4 x L(M ). This proves that L(M) = L(M ). 22 / 25

Example Consider the nondeterministic finite automaton whose graph is given elow. M = ({a, }, {q 0, q 1, q 2 }, δ, q 0, {q 2 }) a q 0 q 1 q 2 a 23 / 25

It is easy to see that the language accepted y this automaton is A A, that is the language that consists of all words that contain two consecutive symols. The graph of the nondeterministic automaton is simpler than the graph of the previous deterministic automaton; this simplification is made possile y the nondeterminism. 24 / 25

Graph of the Equivalent ndfa a a {q 0 } {q 0, q 1 } a a {q 1 } {q 1, q 2 } {q 0, q 1, q 2 } a a {q 2 } {q 0, q 2 } a a 25 / 25