Automata and Languages

Similar documents
Nondeterministic Finite Automata

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.

Lecture 1: Finite State Automaton

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

Chapter Five: Nondeterministic Finite Automata

Lecture 4 Nondeterministic Finite Accepters

Automata and Languages

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

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Lecture 3: Nondeterministic Finite Automata

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

Theory of Computation (I) Yijia Chen Fudan University

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

Nondeterministic Finite Automata

Chapter 6: NFA Applications

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Theory of Languages and Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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,

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

Finite Automata. Seungjin Choi

Algorithms for NLP

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

Deterministic Finite Automaton (DFA)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 455/555: Finite automata

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

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Nondeterministic finite automata

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

Nondeterminism and Epsilon Transitions

Theory of Computation

Course 4 Finite Automata/Finite State Machines

CS243, Logic and Computation Nondeterministic finite automata

Inf2A: Converting from NFAs to DFAs and Closure Properties

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

CS21 Decidability and Tractability

Java II Finite Automata I

Intro to Theory of Computation

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

Finite Automata and Regular languages

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

UNIT-III REGULAR LANGUAGES

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

Introduction to Languages and Computation

Lecture 2: Regular Expression

CMSC 330: Organization of Programming Languages

Equivalence of DFAs and NFAs

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

Decision, Computation and Language

Non-deterministic Finite Automata (NFAs)

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

Uses of finite automata

Finite Automata and Regular Languages (part III)

Sri vidya college of engineering and technology

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

Nondeterminism. September 7, Nondeterminism

Chapter 5. Finite Automata

CPS 220 Theory of Computation Pushdown Automata (PDA)

Finite Automata. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Pushdown Automata: Introduction (2)

Theory of Computation (II) Yijia Chen Fudan University

Lecture 17: Language Recognition

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

FINITE STATE MACHINES (AUTOMATA)

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

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

Nondeterministic Finite Automata and Regular Expressions

Part I: Definitions and Properties

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

Computational Models Lecture 2 1

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

Nondeterministic Finite Automata

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

Finite Automata. Finite Automata

Automata and Languages

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

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

September 7, Formal Definition of a Nondeterministic Finite Automaton

CSE 105 THEORY OF COMPUTATION

ECS 120 Lesson 15 Turing Machines, Pt. 1

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Finite Automata Part Two

Extended transition function of a DFA

THEORY OF COMPUTATION

Constructions on Finite Automata

Turing Machines A Turing Machine is a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where Q, Σ, Γ are all finite

Classes and conversions

Transcription:

Automata and Languages Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Nondeterministic Finite Automata with empty moves (-NFA) Definition A nondeterministic finite automaton with empty moves (-NFA) M is defined by a 5-tuple M=(Q,Σ,δ,q 0,F), with q Q: finite set of states q Σ: finite input alphabet q δ: transition function δ:q (Σ U {}) P(Q) q q 0 Q: start state q F Q: set of final states

Nondeterministic Finite Automata with empty moves (-NFA) Definition A string w is accepted by a -NFA M if and only if there exists a path starting at q 0 which is labeled by w and ends in a final state. The language accepted by a -NFA M is the set of all strings which are accepted by M and is denoted by L (M ). L(M)={w: δ(q 0,w) F Φ}

Notes Nondeterministic Finite Automata with empty moves (-NFA) δ : Q ( Σ { }) P( Q) A -transition causes the machine to change its state non-deterministically, without consuming any input. q q 2

Notes Nondeterministic Finite Automata with empty moves (-NFA) A -NFA has transition rules/possibilities like: q q 2 And q : q 2 q 3 : Empty string transition Nondeterministic transition

Nondeterministic Finite Automata with empty moves (-NFA) Nondeterminism ~ Parallelism For any string w, the nondeterministic automaton can be in a subset Q of several possible states. If the final set contains a final state, then the automaton accepts the string. The automaton processes the input in a parallel fashion; its computational path is no longer a line, but more like a tree.

Nondeterministic Finite Automata with empty moves (-NFA) We can write the NFA in two ways. State digraph a b q0 b q q2 2. Table δ : Q ( Σ { }) P( Q) δ a b q0 {q0} {q0,q} φ q φ φ {q2} q2 φ φ φ

Nondeterministic Finite Automata with empty moves (-NFA) Example 0, 0, 0, q q 2 q 3 q 4 This automaton accepts 00, because there is a possible path that leads to a final state, namely: q q q 2 q 3 q 4 q 4 (note that q q q q q is not accepting)

Nondeterministic Finite Automata with empty moves (-NFA) Example 0, 0, 0, q q 2 q 3 q 4 The string gets rejected: on the automaton can only reach: {q,q 2,q 3 }.

Example Difference between NFA and -NFA 0, 0, -NFA: 0, q q 2 q 3 0, q 4 0, NFA: 0 q q 2 q 3 q 4 The string is accepted by the above -NFA And rejected by the above NFA

Nondeterministic Finite Automata with empty moves (-NFA) Example a a start b b A -transition is taken without consuming any character from the input. What does the NFA above accepts? aa*+bb*

Quiz Nondeterministic Finite Automata with empty moves (-NFA) M : M 2 : M 3 : q 0 q 0 q q 0 q 2 M 4 : 0 q 0, q 0 q 3 q 2 What are δ(q 0,0), δ(q 0,), δ(q 0, ) in each of M, M 2, M 3 and in M 4.?

Nondeterministic Finite Automata with empty moves (-NFA) Answer M: M2: M3: q 0 q 0 q q 0 q 2 M4: 0 q 0, q 0 q 3 q 2 M: δ(q 0,0) = δ(q 0,) = δ(q 0, ) = M2: Same M3: δ(q 0,0) = δ(q 0,) =, δ(q 0, ) = {q,q 2 } M4: δ(q 0,0)={q,q 3 }, δ(q 0,)={q 2,q 3 }, δ(q 0, )=

Quiz Nondeterministic Finite Automata with empty moves (-NFA) 0 q 0, q 0 q 3 q 2 Which of the following strings is accepted?. 2. 0 3. 4. 0

Nondeterministic Finite Automata with empty moves (-NFA) Answer 0 q 0, q 0 q 3 q 2.. is rejected. No path labeled by empty string from start state to an accept state. 2. 0 is accepted. EG the path 3. is accepted. EG the path 4. 0 is accepted. There is only one accepted path: q q 0 0 q 0 q3 q 0 q3 q2 q3 q2 q3 q2 q3 0

Nondeterministic Finite Automata with empty moves (-NFA) Definition Given a -NFA state s, the -closure(s) is the set of states that are reachable through -transition from s. -closure(s)={q: there is a path from s to q labeled } Given a set of -NFA states T, the -closure(t) is the set of states that are reachable through -transition from any state s T. -closure(t)=u s T -closure(s)

Nondeterministic Finite Automata with empty moves (-NFA) Example : 0 2 q 0 q q 2 -closure(q 0 ) = {q 0,q, q 2 } -closure(q ) = {q, q 2 } -closure(q 2 ) = {q 2 }

Nondeterministic Finite Automata with empty moves (-NFA) Example 2: i f 2 3 any character IF 4 5 error a-z a-z 4 5 6 7 0-9 0-9 0-9 9 0 2 8 NUM 3 ID What states can be reached from state without consuming a character?

Nondeterministic Finite Automata with empty moves (-NFA) Example i f 2 3 any character IF 4 5 error a-z a-z 4 5 6 7 0-9 0-9 0-9 9 0 2 8 NUM 3 ID What states can be reached from state without consuming a character? {,4,9,4} form the -closure of state

Nondeterministic Finite Automata with empty moves (-NFA) Example i 2 3 f any character IF 4 5 a-z 4 5 6 7 error What are all the state closures in this NFA? a-z 0-9 0-9 0-9 9 0 2 8 NUM 3 ID closure() = {,4,9,4} closure(5) = {5,6,8} closure(8) = {6,8} closure(7) = {6,7,8} closure(0) = {0,,3} closure(3) = {,3} closure(2) = {,2,3}

Nondeterministic Finite Automata with empty moves (-NFA) Definition: Extension of δ δ : Q ( { }) P( Q) * δ : Q P( Q) δ is defined as follows:. (q,)=-closure(q) δ 2. (q,wa)=-closure(t) where δ T={p: p δ(r,a) and r δ (q,w)}, a Σ, w Σ*

Nondeterministic Finite Automata with empty moves (-NFA) Example: Extension of δ 0 2 q 0 q q 2 δ (q 0, 0) = {q, q 2 }

-NFA è NFA Theorem: For every language L that is accepted by a -NFA, there is an NFA that accepts L as well. -NFA and NFA are equivalent computational models.

-NFA è NFA Proof: Let M=(Q,Σ,δ,q 0,F) be a -NFA, an equivalent NFA, M =(Q,Σ,δ,q 0,F ) can be constructed as follows:. F ' = { F { q 0 } F If -closure(q 0 ) Otherwise F Φ ˆ( 2. δ '( q, a) = δ q, a)

-NFA è NFA Example: For the -NFA: 0 2 q 0 q q 2 Construct the equivalent NFA? Answer: Given -NFA Q={q 0,q,q 2 } and Σ={0,,2} -closure(q 0 )={q 0,q,q 2 } F Φ δ ( q,0) = ˆ( δ,0) = {q 0,q,q 2 } ' 0 q0 δ ( q,) = ˆ( δ,) = {q,q 2 } ' 0 q0 δ ( q,2) = ˆ( δ,2) = {q 2 } ' 0 q0 0 Constructed NFA Q={q 0,q,q 2 } and Σ={0,,2} 0, F = {q 0,q 2 } q 0 q q 2 0,,2

-NFA è NFA Example: For the -NFA: 0 2 q 0 q q 2 Construct the equivalent NFA? Answer: Given -NFA Q={q 0,q,q 2 } and Σ={0,,2} -closure(q 0 )={q 0,q,q 2 } F Φ δ ( q,0) = ˆ( δ,0) = Φ ' q δ ( q,) = ˆ( δ,) = {q,q 2 } ' q δ ( q,2) = ˆ( δ,2) = {q 2 } ' q Constructed NFA Q={q 0,q,q 2 } and Σ={0,,2} F = {q 0,q } 0 0,,2 q 0 q q 2 0,,2

-NFA è NFA Example: For the -NFA: 0 2 q 0 q q 2 Construct the equivalent NFA? Answer: Given -NFA Q={q 0,q,q 2 } and Σ={0,,2} -closure(q 0 )={q 0,q,q 2 } F Φ δ ( q,0) = ˆ( δ,0) = Φ ' 2 q2 δ ( q,) = ˆ( δ,) = Φ ' 2 q2 δ ( q,2) = ˆ( δ,2) = {q 2 } ' 2 q2 Constructed NFA Q={q 0,q,q 2 } and Σ={0,,2} F = {q 0,q } 0 0,,2 q 0 q q 2 0,,2 2

-NFA è NFA Example: For the -NFA: 0 2 q 0 q q 2 Construct the equivalent NFA? Answer: q 0 q q 2 0 2 0,,2 0,,2

RE è -NFA Theorem: Let r be RE, there exist a -NFA that accepts L(r).

RE è -NFA Proof: The proof works by induction, using the recursive definition of regular expressions. RE -NFA Φ q 0 q 0 a q 0 a q

RE è -NFA Proof: M M2 r+r2 è L(M) U L(M2) M r*è L(M)* M M2 r.r2 è L(M) L(M2)

RE è -NFA Example For the regular expression r=if we build the -NFA as follows: The -NFA for a symbol i is: start i 2 The -NFA for a symbol f is: start f 2 The -NFA for the regular expression if is: start i 2 f 3 IF

RE è -NFA Example 2 For the regular expression r=0+* build the equivalent -NFA? The -NFA for a symbol 0 is: 0 The -NFA for a symbol is: The -NFA for a symbol * is: The -NFA for the regular expression 0+* is:

RE è -NFA Example 2 For the regular expression r=0+* build the equivalent -NFA? The -NFA for the regular expression 0+* is: * 0+* 0 0

RE è -NFA Example 3 Q: Find an NFA for the regular expression (0 )*(0000000 (0 )*)(0 )*

RE è -NFA Example 3 (0 )*(0000000 (0 )*)(0 )* Note that: in this example ε =

RE è -NFA Exercise Construct a -NFA for the regular expression: 00*+(+0)*+0*