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

Similar documents
Theory of Computation (I) Yijia Chen Fudan University

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

Inf2A: Converting from NFAs to DFAs and Closure Properties

Computational Models Lecture 2 1

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Computational Models Lecture 2 1

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Lecture 1: Finite State Automaton

Nondeterministic Finite Automata

Lecture 3: Nondeterministic Finite Automata

Computational Models - Lecture 1 1

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

Theory of Languages and Automata

Finite Automata and Regular languages

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

Non-deterministic Finite Automata (NFAs)

Computational Models - Lecture 5 1

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Non-Deterministic Finite Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

Theory of Computation (II) Yijia Chen Fudan University

C2.1 Regular Grammars

C2.1 Regular Grammars

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Automata and Languages

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

CS 455/555: Finite automata

Computational Models: Class 5

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

Chapter Five: Nondeterministic Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

Classes and conversions

CS 154, Lecture 3: DFA NFA, Regular Expressions

Equivalence of DFAs and NFAs

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

Nondeterministic Finite Automata

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

CSE 105 Theory of Computation Professor Jeanne Ferrante

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

CS243, Logic and Computation Nondeterministic finite automata

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

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

CMSC 330: Organization of Programming Languages

Regular Expressions. Definitions Equivalence to Finite Automata

Regular Expressions Kleene s Theorem Equation-based alternate construction. Regular Expressions. Deepak D Souza

Intro to Theory of Computation

Nondeterministic Finite Automata. Nondeterminism Subset Construction

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

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

Critical CS Questions

CS 154 Formal Languages and Computability Assignment #2 Solutions

Finite Automata and Regular Languages (part III)

Computational Models - Lecture 4

Constructions on Finite Automata

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Fooling Sets and. Lecture 5

Extended transition function of a DFA

Nondeterministic Finite Automata

Lecture 4 Nondeterministic Finite Accepters

Nondeterministic finite automata

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 )

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Lecture 2: Regular Expression

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

Closure under the Regular Operations

Sri vidya college of engineering and technology

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

Computational Models - Lecture 3 1

What we have done so far

Computational Models: Class 1

Chapter 6: NFA Applications

Computational Models: Class 3

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

TWO-WAY FINITE AUTOMATA & PEBBLE AUTOMATA. Written by Liat Peterfreund

CS21 Decidability and Tractability

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,

Constructions on Finite Automata

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Decision, Computation and Language

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

Computational Models #1

Computational Models - Lecture 3 1

Parsing Regular Expressions and Regular Grammars

Finite Automata and Regular Languages

Time Magazine (1984)

Uses of finite automata

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

Pushdown Automata. Reading: Chapter 6

UNIT-III REGULAR LANGUAGES

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

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

Transcription:

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular Expressions Orit Moskovich Gal Rotem Tel Aviv University October 28, 2015 Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 1 / 22

Overview 1 Non Deterministic Finite Automata (NFA) 2 DFA and NFA Equivalence 3 Regular Expressions 4 Closure Under Operations Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 2 / 22

Reminder - Deterministic Finite Automata (DFA) Definition 1 A deterministic finite automaton is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a finite set called the states Σ is a finite set called the alphabet δ : Q Σ Q is the transition function q 0 Q is the initial state F Q is the set of accepting states Definition 2 A language L is regular there exists a DFA M that accepts it, i.e., L(M) = L Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 3 / 22

Non Deterministic Finite Automata (NFA) Definition 3 P(Q) is the power set of Q Definition 4 Σ ε = Σ {ε} Definition 5 A non deterministic finite automaton is a 5-tuple N = (Q, Σ ε, δ, q 0, F) Q is a finite set called the states Σ ε is a finite set called the alphabet δ : Q Σ ε P(Q) is the transition function q 0 Q is the initial state F Q is the set of accepting states Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 4 / 22

Non Deterministic Finite Automata (NFA) Definition 6 N accepts w Σ δ(q 0, w) F. I.e., if at least one of the computation routes ends in an accepting state. Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 5 / 22

DFA and NFA Equivalence Theorem 7 A language L is regular there exists an NFA N that accepts it Construction: NFA DFA Let N = (Q, Σ, δ, q 0, F ) be an NFA. We construct an equivalent DFA M = (Q, Σ, δ, q 0, F ). Q = P(Q) R Q, σ Σ. δ (R, σ) = q 0 = {q 0} q R δ(q, σ) F = {R Q R contains an accepting state} ( ) we ignore for now ε transitions Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 6 / 22

Example Example 8 Build an NFA for the following language: L 1 = {all words of length 2 that the letter before last is 0} Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 7 / 22

Example Example 9 Build the DFA from the NFA previously built for L 1 = {all words of length 2 that the letter before last is 0} Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 8 / 22

Regular expressions Definition 10 R is a regular expression over Σ if R is in the form of: σ for some σ Σ ε R 1 R 2 for regular expressions R 1 and R 2 R 1 R 2 for regular expressions R 1 and R 2 R1 for regular expression R 1 Definition 11 L(R) is the language defined by the regular expression R Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions 28, 2015 9 / 22

Example Example 12 Build a regular expression for the language: L 1 = {all words of length 2 that the letter before last is 0} Regular expression: Σ 0(0 1) Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 10 / 22

Example Example 13 Build an NFA and a regular expression for the following language: L 2 = {all words of that start with 0 or end with 1} Regular expression: 0Σ Σ 1 Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 11 / 22

Example Example 14 Build the DFA from the NFA previously built for L 2 = {all words of that start with 0 or end with 1} Step 1: eliminate ε transitions Step 2: DFA... Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 12 / 22

Closure Under Reverse Example 15 Define the operation: Reverse(L) = {w R w L} where w = x 1... x n, then w R = x n... x 1. Prove that regular languages are closed under Reverse. Proof. Let L be a regular language and let M = (Q, Σ, δ, q 0, F) be a DFA that accepts it. We build an NFA N Reverse s.t L(N Reverse ) = Reverse(L). Intuition? Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 13 / 22

Closure Under Reverse (Cont.) Proof (Cont.) Intuition? Start by reversing all transitions: Note that this is no longer a DFA... Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 14 / 22

Closure Under Reverse (Cont.) Proof (Cont.) Then add a new initial state, with an ε transition for all previously accepting states: Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 15 / 22

Closure Under Reverse (Cont.) Proof (Cont.) Recall, M = (Q, Σ, δ, q 0, F) be a DFA that accepts L. Then, define Where, N Reverse = (Q {s}, Σ ε, δ, s, F ) s is the new initial state δ = (1) δ (s, ε) = F (2) q Q, σ Σ. δ (q, σ) = {r Q δ(r, σ) = q} F = {q 0 } Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 16 / 22

Closure Under Reverse (Cont.) Proof (Cont.) Claim: L(N Reverse ) = Reverse(L) Proof: w R = x n... x 1 Reverse(L) w = x 1... x n L x q 0,..., q n Q. q 1 x 0 2 x q1... n qn where q n F (accepting route in M) x n s ε q }{{ n qn 1... x 1 q }}{{ 0 } (1) (2) where q 0 F w R = x n... x 1 L(N Reverse ) Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 17 / 22

Closure Under DropChar Example 16 Define the operation: DropChar(L) = {w 1 w 2 w 1, w 2 Σ and σ Σ. w 1 σw 2 L} Prove that regular languages are closed under DropChar Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 18 / 22

Closure Under DropChar (Cont.) Proof. Let L be a regular language and let M = (Q, Σ, δ, q 0, F) be a DFA that accepts it. We build an NFA N drop s.t L(N drop ) = DropChar(L): N drop = (Q {1, 2}, Σ ε, δ, (q 0, 1), F 2) Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 19 / 22

Closure Under DropChar (Cont.) Proof (Cont.) Formally, ) ( ) q Q, σ Σ. δ ((q, 1), σ = δ(q, σ), 1 ) ( ) q Q, σ Σ. δ ((q, 2), σ = δ(q, σ), 2 ) { ( ) } q Q. δ ((q, 1), ε = δ(q, σ), 2 σ Σ Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 20 / 22

Closure Under DropChar (Cont.) Proof (Cont.) Claim: L(N drop ) = DropChar(L) Proof: w DropChar(L) w 1, w 2 Σ. w = w 1 w 2 and σ Σ. w 1 σw 2 L w 1 σw 2 L(M) q 1, q 2 Q, q f F. (i) δ(q 0, w 1 ) = q 1 (ii) δ(q 1, σ) = q 2 (iii) δ(q 2, w 2 ) = q f (i) δ ((q 0, 1), w 1 ) (q 1, 1) (ii) δ ((q 1, 1), ε)) (q 2, 2) (iii) δ ((q 2, 2), w 2 ) = {(q f, 2)} w 1 w 2 L(N drop ) Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 21 / 22

The End Recitation 2 - Non Deterministic Finite Automata (NFA) and October Regular 28, Expressions 2015 22 / 22