Equivalence of DFAs and NFAs

Similar documents
CS 154. Finite Automata, Nondeterminism, Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

Intro to Theory of Computation

CS 154, Lecture 3: DFA NFA, Regular Expressions

CS 455/555: Finite automata

Theory of Computation (I) Yijia Chen Fudan University

Minimization of DFAs

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

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

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

Lecture 3: Nondeterministic Finite Automata

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Nondeterministic Finite Automata

Chapter Five: Nondeterministic Finite Automata

CSE 105 Theory of Computation Professor Jeanne Ferrante

Inf2A: Converting from NFAs to DFAs and Closure Properties

Finite Automata and Regular languages

CS 154 Introduction to Automata and Complexity Theory

Closure under the Regular Operations

Computational Models Lecture 2 1

Non-deterministic Finite Automata (NFAs)

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

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

Computational Models Lecture 2 1

CSE 105 THEORY OF COMPUTATION

Chapter 5. Finite Automata

CSE 105 THEORY OF COMPUTATION

Constructions on Finite Automata

Lecture 7 Properties of regular languages

CSE 105 THEORY OF COMPUTATION

Lecture 1: Finite State Automaton

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

CSE 105 THEORY OF COMPUTATION

Nondeterministic finite automata

CPS 220 Theory of Computation REGULAR LANGUAGES

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

3515ICT: Theory of Computation. Regular languages

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

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

CSE 105 THEORY OF COMPUTATION

CSC173 Workshop: 13 Sept. Notes

Deterministic Finite Automata (DFAs)

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

Sri vidya college of engineering and technology

Fooling Sets and. Lecture 5

1 More finite deterministic automata

Lecture 4 Nondeterministic Finite Accepters

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,

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

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

Constructions on Finite Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

CSE 105 THEORY OF COMPUTATION

Theory of Computation (II) Yijia Chen Fudan University

Closure under the Regular Operations

Computational Models - Lecture 1 1

Finite Automata Part Two

Deterministic Finite Automata (DFAs)

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

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

Advanced Automata Theory 2 Finite Automata

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

CS21 Decidability and Tractability

Computer Sciences Department

CSCI 2670 Introduction to Theory of Computing

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

Uses of finite automata

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

Theory of Computation 4 Non-Deterministic Finite Automata

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

CS 208: Automata Theory and Logic

CSE 105 THEORY OF COMPUTATION

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

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

CSC236 Week 10. Larry Zhang

Automata and Languages

Sanjit A. Seshia EECS, UC Berkeley

Theory of Languages and Automata

Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION

Classes and conversions

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Deterministic Finite Automata (DFAs)

Finite State Transducers

CS243, Logic and Computation Nondeterministic finite automata

Closure Properties of Regular Languages

Theory of Computation Lecture 1. Dr. Nahla Belal

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

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Chapter 6: NFA Applications

Formal Models in NLP

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Further discussion of Turing machines

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Transcription:

CS 172: Computability and Complexity Equivalence of DFAs and NFAs It s a tie! DFA NFA Sanjit A. Seshia EECS, UC Berkeley Acknowledgments: L.von Ahn, L. Blum, M. Blum

What we ll do today Prove that DFAs and NFAs are equally expressive Use that to prove closure of other regular operations Introduction to regular expressions S. A. Seshia 2

Recap: Closure If you perform an operation on one/more regular languages, is the result also a regular language? S. A. Seshia 3

Operations on Regular Languages Given: Two regular languages A and B Union: A B = {w w A or w B} Intersection: A B =? Complementation: A = {w w A} Reverse: A R = {w 1 w 2 w k w k w k-1 w 1 A} Concatenation: A B = {vw v A and w B} Star: A * = {w 1 w 2 w k k 0 and each w i A} S. A. Seshia 4

Closure under Reverse Reverse: A R = {w 1 w 2 w k w k w k-1 w 1 A} Regular languages are closed under reverse. Here s an attempt to prove it: Given M that recognizes A What if you could run it backwards? Construct M R as M with all arrows reversed & accept state interchanged with start state M R is an NFA S. A. Seshia 5

A non-deterministic finite automaton (NFA) is also a 5-tuple M = (Q, Σ, δ, q 0, F) Q is the set of states Σ is the alphabet δ : Q Σ ε 2Q q 0 Q is the start state is the transition function F Q is the set of accept states 2 Q is the set of subsets of Q and Σ ε = Σ {ε} S. A. Seshia 6

Tree of Computations Deterministic Computation Non-Deterministic Computation stuck accept or reject accept reject S. A. Seshia 7

Equivalence Two automata are equivalent if their languages are the same For M 1, M 2, L(M 1 ) = L(M 2 ) DFAs and NFAs: For every NFA there is an equivalent DFA (we ll prove this) and vice-versa (this is easy, why?) S. A. Seshia 8

Theorem: Every NFA has an equivalent DFA Corollary: A language is regular iff it is recognized by an NFA Corollary: L is regular iff L R is regular (need to also prove that M R recognizes L R ) S. A. Seshia 9

From NFA to DFA Proof Hints: Proof by construction Given an arbitrary NFA N, construct an equivalent DFA M Proof by induction N accepts a word w iff M accepts w S. A. Seshia 10

FROM NFA TO DFA Input: N = (Q, Σ, δ, q 0, F) Output: M = (Q, Σ, δ, q 0, F ) Q =? S. A. Seshia 11

From NFA to DFA Input: N = (Q, Σ, δ, q 0, F) Output: M = (Q, Σ, δ, q 0, F ) reject Idea: Q = 2 Q accept Assume (for now) that there are no ε-transitions Each non-stuck path in the computation tree is of equal length Do a BFS (breadth-first search) on this tree, tracking the set of states transitioned to S. A. Seshia 12

0, 1 NFA Example 0,1 1 1 1 q 0 q 1 q 2 q 3 Run on 1110 S. A. Seshia 13

reject Input: N = (Q, Σ, δ, q 0, F) Output: M = (Q, Σ, δ, q 0, F ) 0 ε a 1 2 a ε 3 4 b ε b 6 7 5 b 8 c c ε accept From NFA to DFA Idea: Q = 2 Q What if we had ε-transitions? S. A. Seshia 14

From NFA to DFA Input: N = (Q, Σ, δ, q 0, F) Output: M = (Q, Σ, δ, q 0, F ) 0 ε a 1 2 a ε 3 4 b ε b 6 7 5 b 8 c c reject ε accept Idea: Q = 2 Q What if we had ε-transitions? After reading an input symbol, follow ε-transitions until you can t any more Given a set S in 2 Q, E(S) is the set of all states reached from S by following ε-transitions - E(S) is called the ε-closure of S S. A. Seshia 15

0, 1 NFA Example 0,1 1 1,ε 1 q 0 q 1 q 2 q 3 Run on 1110 S. A. Seshia 16

From NFA to DFA Input: N = (Q, Σ, δ, q 0, F) Output: M = (Q, Σ, δ, q 0, F ) Q = 2 Q δ : Q Σ Q δ (R,σ) = E( δ(r,σ) ) q 0 =? F =? r R S. A. Seshia 17

From NFA to DFA Input: N = (Q, Σ, δ, q 0, F) Output: M = (Q, Σ, δ, q 0, F ) Q = 2 Q δ : Q Σ Q δ (R,σ) = E( δ(r,σ) ) r R q 0 = E({q 0 }) F = { R Q f R for some f F } (read details of the construction in Sipser) S. A. Seshia 18

From NFA N to DFA M Construction is complete But the proof isn t: Need to prove N accepts a word w iff M accepts w Use structural induction on the length of w, w Base case: w = 0 Induction step: Assume for w = n, prove for w = n+1 S. A. Seshia 19

Useful Definition Let w Σ * For an NFA N: ^ δ(q, w) = set of states reached by executing N on w starting from q Note that a state of N is in Q For the corresponding DFA M: ^ δ (q, w) = state reached by executing M on w starting from q Note that a state of M is in 2 Q S. A. Seshia 20

NFA to DFA: Complexity If the original NFA N has n states, how large can the corresponding DFA M be? S. A. Seshia 21

NFA to DFA: Complexity If the original NFA N has n states, how large can the corresponding DFA M be? Answer: 2 n states Exercise: construct an example where N has n states and M has Θ(2 n ) states S. A. Seshia 22

Remaining Operations Given: Two regular languages A and B Concatenation: A B = {vw v A and w B} Star: A * = {w 1 w 2 w k k 0 and each w i A} S. A. Seshia 23

Closure under Concatenation Given DFAs M 1 and M 2, how can we construct an NFA N for L(M 1 ) L(M 2 )? S. A. Seshia 24

Closure under Concatenation Given DFAs M 1 and M 2, construct NFA N by connecting all accept states in M 1 to start states in M 2 What are accept states of N? S. A. Seshia 25

Closure under Star Let L be a regular language and M be a DFA for L How do we construct an NFA N that recognizes L*? ε 0 0,1 1 ε 1 0 0 1 ε S. A. Seshia 26

Closure under Star Why not the following? ε 0 0,1 1 1 0 0 1 ε S. A. Seshia 27

Formally: Input: DFA M = (Q, Σ, δ, q 1, F) Output: NFA N = (Q, Σ, δ, {q 0 }, F ) Q = Q {q 0 } F = F {q 0 } δ (q,a) = {δ(q,a)} {q 1 } {q 1 } if q Q and a ε if q F and a = ε if q = q 0 and a = ε if q = q 0 and a ε else S. A. Seshia 28

REGULAR LANGUAGES ARE CLOSED UNDER REGULAR OPERATIONS Union: A B = { w w A or w B } Intersection: A B = { w w A and w B } Reverse: A R = { w 1 w k w k w 1 A } Complementation: A = { w w A } Concatenation: A B = { vw v A and w B } Star: A* = { w 1 w k k 0 and each w i A } S. A. Seshia 29

Regular Expressions S. A. Seshia 30

What does Language D look like? D = { w w has equal number of occurrences of 01 and 10} w should toggle between 0 and 1 an equal number of times How about: 0, 1, 011, 0110, ε -- are they in D? S. A. Seshia 31

What does Language D look like? D = { w w has equal number of occurrences of 01 and 10} = { w w = 1, w = 0, w = ε or w starts with a 0 and ends with a 0 or w starts with a 1 and ends with a 1 } 1 0 ε (0Σ*0) (1Σ*1) Σ = {0,1} S. A. Seshia 32

REGULAR EXPRESSIONS σ is a regular expression representing {σ} ( σ Σ) ε is a regular expression representing {ε} is a regular expression representing If R 1 and R 2 are regular expressions representing L 1 and L 2 then: (R 1 R 2 ) represents L 1 L 2 (R 1 R 2 ) represents L 1 L 2 (R 1 )* represents L 1 * S. A. Seshia 33

Next Steps Read Sipser 1.3 in preparation for next lecture S. A. Seshia 34