Chapter 2 Finite Automata

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Topics Automata Theory Grammars and Languages Complexities
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Finite-State Machines with No Output
NFA ε - NFA - DFA equivalence. What is an NFA An NFA is an automaton that its states might have none, one or more outgoing arrows under a specific symbol.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CS 3813: Introduction to Formal Languages and Automata Chapter 2 Deterministic finite automata These class notes are based on material from our textbook,
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
NFA defined. NFA A Non-deterministic Finite-state Automata (NFA) is a language recognizing system similar to a DFA. It supports a level of non-determinism.
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Modeling Computation: Finite State Machines without Output
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Lecture Notes 
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
Converting Regular Expressions to NFAs Empty string   is a regular expression denoting  {  } a is a regular expression denoting {a} for any a in 
Acceptance by DFA. Defining DFAs For each description let’s draw a DFA that recognizes the language it describes { aa,ab,ac} {  a, abb, abbbb, …,ab.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lexical analysis Finite Automata
Pushdown Automata.
Deterministic Finite Automata
Two issues in lexical analysis
Recognizer for a Language
Chapter 2 FINITE AUTOMATA.
Jaya Krishna, M.Tech, Assistant Professor
REGULAR LANGUAGES AND REGULAR GRAMMARS
Hierarchy of languages
Non-Determinism 12CS45 Finite Automata.
Some slides by Elsa L Gunter, NJIT, and by Costas Busch
CS 154, Lecture 3: DFANFA, Regular Expressions.
Principles of Computing – UFCFA3-30-1
Deterministic Finite State Automata
Non-Deterministic Finite Automata
Theory of Computation Lecture #
NFAs and Transition Graphs
Finite Automata Reading: Chapter 2.
Finite Automata.
4b Lexical analysis Finite Automata
Chapter Five: Nondeterministic Finite Automata
Finite Automata & Language Theory
Discrete Math II Howon Kim
Chapter 3. Lexical Analysis (2)
4b Lexical analysis Finite Automata
Instructor: Aaron Roth
CSC312 Automata Theory Transition Graphs Lecture # 9
Chapter 1 Regular Language
NFAs and Transition Graphs
Lexical Analysis Uses formalism of Regular Languages
What is it? The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled.
Presentation transcript:

Chapter 2 Finite Automata

A Finite-State Machine (1) A finite state machine is a mathematical model of a system, with discrete inputs and outputs

A Finite-State Machine (2) Finite Automata FA: a finite set of states a set of transitions (edges) a start state a set of final states Defining a FA is a kind of programming. Problem definition Includes defining possible actions & accepting condition. States  structure of program Includes designating which are initial & final. Transitions  program

2.1: Deterministic Finite Automata (1) DFA M = (Q, S, d, q0, F) Q = a finite set of states S = a finite set called the alphabet d = transition function total function Q  S  Q q0 = start state q0  Q F = final or accepting states F  Q

Deterministic Finite Automata (2) DFA M Q = {q0, q1} S = {a, b} F = {q1} The transition function d is given in a tabular form called the transition table d(q0, a) = q1 d(q0, b) = q0 d(q1, a) = q1 d(q1, b) = q0

Deterministic Finite Automata (3) A DFA M can be considered to be a language acceptor. The language of M, L(M), is the set of strings S* accepted by M. A DFA M reads an input string from left to right. The next state depends on the current state and the unread (unprocessed) symbol.

Deterministic Finite Automata (5) The DFA M accepts the set of strings over {a, b} that contain the substring bb M : Q = {q0, q1, q2}, S = {a, b}, F = {q2} The transition function d is given in a tabular form called the transition table d(q0, a) = q0 d(q0, b) = q1 d(q1, a) = q0 d(q1, b) = q2 d(q2, a) = q2 d(q2, b) = q2 Is abba  L(M)? Yes, since the computation halts in state q2, which is a final state Is abab  L(M)? No, since the computation halts in state q1, which is NOT a final state

Deterministic Finite Automata (6) Extended transition function d* of a DFA with transition function d is a function from Q  S*  Q defined recursively on the length of the input string w Basis: |w| = 0. Then w = e and d*(qi, e) = qi Recursive step: Let |w| = 1. Then d*(qi, av) = d*(d(qi, a), v)  qi  Q,  a  S,  v  S*

Deterministic Finite Automata (7) A string w is accepted if d*(q0, w)  F The language of a DFA M is L(M) = {w  S* | d*(q0, w)  F} DFA M = (Q, S, d, q0, F) accepts w  S*  d*(q0, w)  F

Deterministic Finite Automata (8) Two possibilities for DFA M running on w M accepts w M accepts w iff the computation of M on w ends up (halts) in an accepting configuration d*(q0, w)  F M rejects w M rejects w iff the computation of M on w ends up (halts) in a rejecting configuration d*(q0, w)  F

State Diagrams and Examples (1) The state diagram of a DFA M = (Q, S, d,q0, F) is a labeled graph G defined by the following conditions: The nodes of G are the elements of Q The labels on the arcs of G are elements of S q0 is the start node, denoted by F is the set of accepting nodes, denoted by There is an arc from node qi to qj labeled a if d(qi, a) = qj For every node qi and symbol a  S, there is exactly one arc labeled a leaving qi a q0

State Diagrams and Examples (2) Deterministic Finite Automata DFA all outgoing edges are labelled with an input character no state has e- transition, transition on input e no two edges leaving a given state have the same label for each state s and input symbol a, there is at most one edge label a leaving s Therefore: the next state can be determined uniquely, given the current state and the current input character

State Diagrams and Examples (1) strings over {a,b} with at least 3 a’s 1 a 2 a 3+ a 0 a a b S

State Diagrams and Examples (2) strings over {a,b} with length mod 3 = 0 1 2 S

State Diagrams and Examples (3) strings over {a,b} without 3 consecutive a’s A simple example of “strings not of the form …”. 1 a 2 a Has aaa 0 a a b S

State Diagrams and Examples (4) Draw a state diagram for DFA M that accepts the set of strings over {a, b} that contain the substring bb The string ababb is accepted since the halting state is the accepting state q2 q1 q2 q0 b a a, b

State Diagrams and Examples (5) The DFA accepts (b|ab)*(a|e) the set of strings over {a, b} that do not contain the substring aa b S 0 a a 1 a a 2 a b

State Diagrams and Examples (6) The language {anbn, n0} is not regular, so we can not build a DFA that accept this language It needs an infinite number of states But {anbn, 1  n  3} is regular and its DFA is This DFA is NOT Complete a a a q0 q1 q2 q3 b b b q4 q5 q6 b b

State Diagrams and Examples (7) strings over {a, b} that contain the substring bb OR do not contain the substring aa This language is the union of the languages of the previous examples a 0 a a 1 a a 2 a 2 a b a b a b b 1 b b 2 b S

State Diagrams and Examples (8) strings over {a, b} that contain an even number of a’s AND an odd number of b’s b [ea, eb] [ea, ob] b a a a a [oa, eb] b [oa, ob] b

State Diagrams and Examples (9) Let M be the DFA previous slide A DFA M’ that accepts all strings over {a, b} that do not contain an even number of a’s AND an odd number of b’s is shown below L(M’) = {a, b}* - L(M) = S* - L(M) Any string accepted by M is rejected by M’ and vice versa b [ea, eb] [ea, ob] b a a a a [oa, eb] b [oa, ob] b

State Diagrams and Examples (10) Let S = {0, 1, 2, 3}. A string in S* is a sequence of integers from S The DFA M determines whether the sum of elements of a string is divisible by 4 The string 12302 and 0130 should be accepted and 0111 rejected by M w mod 4 = 0 1 w mod 4 = 1 3 1 3 1 3 2 2 2 2 w mod 4 = 2 1 w mod 4 = 3 3

State Diagrams and Examples (11) DFA M1 accepts (ab)*c M1 is incomplete determinism The string abcc is rejected since M1 is unable to process the final c from state q2 a q0 q1 b c q2 M1

State Diagrams and Examples (12) M2 accepts the same language as M1 in previous example (ab)*c The state qe is the error state (dead end) a q0 q1 b c a, c b q2 qe a, b, c M2 S

State Diagrams and Examples (13) strings over {a,b} with next-to-last symbol = a …aa …ab a …ba …bb e b

State Diagrams and Examples (14) start 3 b 2 1 a What Language is Accepted?

2.2: Nondeterministic Finite Automata (1) A recognizer that takes an input string & determines whether it’s a valid sentence of the language Deterministic : Has at most one action for every given input symbol. Non-Deterministic : Has more than one (or no) alternative action for the same input symbol.

Nondeterministic Finite Automata (2) NFA: Formal Definition NFA M = (Q, S, d, q0, F) Q = a finite set of states S = a finite set alphabet d = transition function total function Q  S  (Q) = 2Q - power set of Q q0 = initial/starting state q0  Q F = final or accepting states F  Q

Nondeterministic Finite Automata (3) start 3 b 2 1 a Q = { 0, 1, 2, 3 } q0 = 0 F = { 3 }  = { a, b } What Language is defined ? What is the Transition Table ? i n p u t a b state { 0, 1 } { 0 } 1  { 2 } 2  { 3 }

Nondeterministic Finite Automata (4) Change in d For an DFA M, d(q, a) results in one and only one state for all states q and alphabet a For an NFA M, d(q, a) can result in a set of states, zero, one, or more states: qi a a qn qi qn qn qj a a qk d(qn, a) = {qi} d(qn, a) = {qi, qj , qk } d(qn, a) = {} = 

Nondeterministic Finite Automata (5) a,b a,b 1 2 3 4 5 a a b a Why is this only an NFA and not an DFA?

Nondeterministic Finite Automata (6) Computing with NFA’s Computations are different We always start from start state. Call it the root of the computation. Then we might go to different states on one symbol. Then from those states to new sets of states, creating a tree-like computation. If one path ends up in a final state, then ACCEPT, else REJECT

Nondeterministic Finite Automata (7) start 3 b 2 1 a Given an input string, we trace moves If no more input & in final state, ACCEPT EXAMPLE: Input: ababb Path 1: 0 -> 0 -> 0 -> 0 -> 0 -> 0 (REJECT) Path 2: 0 -> 0 -> 0 -> 1 -> 2 -> 3 (ACCEPT)

Nondeterministic Finite Automata (8) Extended transition function d* of a NFA with transition function d is a function from Q  S*  2Q (power set) defined recursively on the length of the input string w Basis: |w| = 0. Then w = e and d*(qi, e) = {qi} Recursive step: Let |w| = 1. Then d*(qi, av) = U d*(qj, v), qj  d(qi, a)  qi  Q,  qj  Q , a  S,  v S* The language of a NFA M is L(M) = {w  S* | d*(q0, w)  F ≠ }

NFA (9) The state diagram DFA M1 and NFA M2 accepts (a|b)*bb(a|b)* 2 1 start 2 1 b a M1 start 2 1 b a, b M2

NFA (10) An NFA that accepts string over {a, b} with substring aa or bb There are 2 distinct acceptance paths for the string abaaabb a, b a, b start a 1 a 2 b a, b 3 b 4

NFA (11) The state diagram DFA M1 and NFA M2 accepts (a|b)*abba(a|b)* start a 1 b 2 b 3 a 4 a b a, b a, b M2 start a 1 b 2 b 3 a 4

NFA with e-Transitions (1) NFA with e-transitions, denoted by NFA-e Formal Definition NFA-e M = (Q, S, d, q0, F) Q = a finite set of states S = a finite set alphabet d = transition function total function Q  (S  {e})  (Q) q0 = initial/starting state q0  Q F = final or accepting states F  Q  transitions j i  Switch state but do not use any input symbol

e-Transitions (2) The input string w is accepted using NFA-e if there is a computation that processes the entire string and halts in an accepting state A computation may continue using e-transition after the input string has been completely processed

e-Transitions (3) L(M1) = (a|b)*bb(a|b)*, L(M2) = (b|ab)*(a|e) L(M) = L(M1)  L(M2) b a, b a, b a q2,0 q2,1 q1,0 b q1,1 b q1,2 M2 M1 b a, b a, b q1,0 b q1,1 b q1,2  M b  a q2,0 q2,1 b

e-Transitions (4) L(M1) = (a|b)*bb(a|b)*, L(M2) = (b|ab)*(a|e) L(M) = L(M1)L(M2) b a, b a, b a q2,0 q2,1 q1,0 b q1,1 b q1,2 M2 M1 b b a, b a, b a q1,0 b q1,1 b q1,2  q2,0 q2,1 M b

e-Transitions (5) M accepts all strings over {a, b} of even length e q0 a, b q1 a, b q2 e

e-Transitions (6) Let M1 and M2 be 2 NFA-e’s as follows q1,0 M1 q1,f q2,0 M2 q2,f M1 = (Q1, S, d1, q1,0, F1) M2 = (Q2, S, d2, q2,0, F2)

e-Transitions (7) L(M) = L(M1)  L(M2) M1   M2 q1,0 M1 q1,f  q0  q2,0 M2 q2,f M = (Q1  Q2  {q0}, S, d, q0, F1  F2) d is the same as in d1 and d2, but add: d(q0, ) = {q1,0, q2,0}

e-Transitions (8) L(M) = L(M1)L(M2)  M1 M2 q1,0 q2,0 M1 q1,f M2 q2,f M = (Q1  Q2, S, d, q1,0, F2) d is the same as in d1 and d2, but add: d(q, ) = {q2,0}, where q  F1

e-Transitions (9) L(M) = L(M1)*  M1 q1,0 q1,f M1  qf q0 M = (Q1  {q0, qf}, S, d, q0, {qf}) d is the same as in d1, but add: d(q0, ) = {q1,0 ,qf} d(q1,f, ) = {q1,0 ,qf}, where q1,f F1

Given the regular expression : a(b*c) | a( b | c+ | e) e-Transitions (10) Given the regular expression : a(b*c) | a( b | c+ | e) Find a transition diagram NFA- that recognizes it.

e-Transitions (11) a( b | c+ | e) 3 2 1 a (b*c) 6 5 7 4 Now that you have the individual diagrams, “or” them as follows:

e-Transitions (12) 3 2 b c a 1 6 5 7 4 

e-Transitions (12) See examples 2.7, 2.8, 2.9, and 2.10

2.3: Equivalence of DFA & NFA (1) Is NFA more powerful than DFA? NO! NFA inefficient to implement directly, so convert to a DFA that recognizes the same strings Is there a language accepted by an NFA that is not accepted by any DFA? No NFA is equivalent to DFA. Each state in DFA corresponds to a SET of states of the NFA

Removing Nondeterminism (2) -closure In an NFA-, the -closure(q) of a state q is the set of all states that can be reached from q by following a path whose edges are all labeled by . a Start   q0 q1 q3 -closure(q0) = {q0, q1, q2, q3} -closure(q1) = {q1, q3} -closure(q2) = {q1, q2, q3}   b b q2

Removing Nondeterminism (3) NFA-e N = (Q, , d, q0, F) -closure(q) : q  Q : set of NFA-e states that are reachable from q on -transitions only -closure(T) : T  Q : NFA-e states reachable from some state t  T on -transitions only move(T, a) : T  Q, a   : set of states to which there is a transition on input a from some state t  T move({q1, q2, …, qi}, a) = (q1, a)  (q2, a)  …  (qi, a) No input is consumed These 3 operations are utilized by algorithms / techniques to facilitate the conversion process

Removing Nondeterminism (4) -closure(0) = {0, 1, 2, 4, 7} (all states reachable from 0 on -moves) -closure(0, 6) = -closure(0)  -closure(6) = {0, 1, 2, 4, 7}  {6, 1, 2, 4,7} = {0, 1, 2, 4, 6, 7} move({0, 1, 2, 4, 7}, a) = {3, 8} (since move(2, a)=3 and move(7, a)=8) 1 2 3 5 4 6 7 8 9 10  a b start

NFA-e DFA with Subset Construction NFA-e N  DFA M construction: Given N = (Q, S, d, q0, F), define M = (Q’, S, d’, q’0, F’) Q’  P(Q), all the possible NFA-e states M could be in. q’0 = e-closure(q0) F’ = {q’  Q’ | q’  F  } d’(q’, a) = e-closure(move(q’, a)) DFA M has a state ERR  Q’ = P(Q) serves as the “error” state, when needed ’(ERR, a) = ERR, a   By definition of ’

Subset Construction Algorithm Concepts 1 2 3 5 4 6 7 8 9 10  a b start Start with NFA-e: (a | b)*abb First we calculate: -closure(0) (i.e., state 0) -closure(0) = {0, 1, 2, 4, 7} (all states reachable from 0 on -moves) Let A = {0, 1, 2, 4, 7} be a state of new DFA M

adds {3, 8} (since move(2, a) = 3 and move(7, a) = 8) Conversion Example (1) 2nd , we calculate : a : -closure(move(A, a)) and b : -closure(move(A, b)) a : -closure(move(A, a)) = -closure(move({0,1,2,4,7}, a))} adds {3, 8} (since move(2, a) = 3 and move(7, a) = 8) From this we have : -closure({3, 8}) = {1,2,3,4,6,7,8} (since 3614, 67, and 12 all by -moves) Let B = {1,2,3,4,6,7,8} be a new state in D. Define M(A, a) = B b : -closure(move(A,b)) = -closure(move({0,1,2,4,7}, b)) adds {5} (since move(4, b) = 5) From this we have : -closure({5}) = {1,2,4,5,6,7} (since 5614, 67, and 12 all by -moves) Let C = {1,2,4,5,6,7} be a new state in D. Define M(A, b) = C

Conversion Example (2) 3rd, we calculate for state B on {a, b} a : -closure(move(B, a)) = -closure(move({1,2,3,4,6,7,8}, a))} = {1,2,3,4,6,7,8} = B Define M(B, a) = B b : -closure(move(B, b)) = -closure(move({1,2,3,4,6,7,8}, b))} = {1,2,4,5,6,7,9} = D Define M(B, b) = D 4th, we calculate for state C on {a, b} a : -closure(move(C, a)) = -closure(move({1,2,4,5,6,7}, a))} = {1,2,3,4,6,7,8} = B Define M(C, a) = B b : -closure(move(C, b)) = -closure(move({1,2,4,5,6,7}, b))} = {1,2,4,5,6,7} = C Define M(C, b) = C

Conversion Example (3) 5th , we calculate for state D on {a, b} a : -closure(move(D, a)) = -closure(move({1,2,4,5,6,7,9}, a))} = {1,2,3,4,6,7,8} = B Define M(D, a) = B b : -closure(move(D, b)) = -closure(move({1,2,4,5,6,7,9}, b))} = {1,2,4,5,6,7,10} = E Define M(D, b) = E Finally, we calculate for state E on {a, b} a : -closure(move(E, a)) = -closure(move({1,2,4,5,6,7,10}, a))} = {1,2,3,4,6,7,8} = B Define M(E, a) = B b : -closure(move(E, b)) = -closure(move({1,2,4,5,6,7,10}, b))} = {1,2,4,5,6,7} = C Define M(E, b) = C

Conversion Example (4) This gives the transition table for the DFA M of: State Input Symbol a b A B C B B D C B C E B C D B E b …b C b b a … A a …a B b …abD b …abbE start a a a

Converting NFA-e to DFA – 2nd Example 8 5 4 7 3 6 2 1  b a c RE: c*(ab)*c* 1st we calculate: -closure(0) -closure(0) = {0, 1, 2, 6, 8} (all states reachable from 0 on -moves) Let A={0, 1, 2, 6, 8} be a state of new DFA M

adds {3} (since move(2, a) = 3) adds {7} (since move(6, c) = 7) Conversion Example (1) 2nd , we calculate : a : -closure(move(A, a)) and b : -closure(move(A, b)) c : -closure(move(A, c)) a : -closure(move(A, a)) = -closure(move({0,1,2,6,8}, a))} adds {3} (since move(2, a) = 3) From this we have : -closure({3}) = {3} (since 33 by -moves) Let B = {3} be a new state. Define M(A, a) = B b : -closure(move(A,b)) = -closure(move({0,1,2,6,8}, b)) There is NO transition on b for all states 0,1,2,6 and 8 Define M(A, b) = Reject c : -closure(move(A, c)) = -closure(move({0,1,2,6,8}, c)) adds {7} (since move(6, c) = 7) From this we have : -closure({7}) = {1,2,5,6,7,8} (since 758, 7512, and 7516 by -moves) Let C = {1,2,5,6,7,8} be a new state. Define M(A, c) = C

adds {4} (since move(3, b) = 4) Conversion Example (2) 3rd , we calculate : a : -closure(move(B, a)) and b : -closure(move(B, b)) c : -closure(move(B, c)) a : -closure(move(B, a)) = -cclosure(move({3}, a))} There is NO transition on a for state 3 Define M(B, a) = Reject b : -closure(move(B, b)) = -closure(move({3}, b)) adds {4} (since move(3, b) = 4) From this we have : -closure({4}) = {1,2,4,5,6,8} (since 458, 4512, and 4516 by -moves) Let D = {1,2,4,5,6,8} be a new state. Define M(B, b) = D c : -closure(move(B, c)) = -closure(move({3}, c)) There is NO transition on c for state 3 Define M(B, c) = Reject

adds {3} (since move(2, a) = 3) adds {7} (since move(6, c) = 7) Conversion Example (3) 4th , we calculate : a : -closure(move(C, a)) and b : -closure(move(C, b)) c : -closure(move(C, c)) a : -cclosure(move(C, a)) = -closure(move({1,2,5,6,7,8},a))} adds {3} (since move(2, a) = 3) -closure({3}) = {3} Define M(C, a) = B b : -closure(move(C, b)) = -closure(move({1,2,5,6,7,8},b)) There is NO transition on b for all states 1,2,5,6, and 7 Define M(C, b) = Reject c : -closure(move(C, c)) = -closure(move({1,2,5,6,7,8},c)) adds {7} (since move(6, c) = 7) From this we have : -closure({7}) = {1,2,5,6,7,8} (since 758, 7512, and 7516 by -moves) Define M(C, c) = C

adds {3} (since move(2, a) = 3) adds {7} (since move(6, c) = 7) Conversion Example (4) 5th , we calculate : a : -closure(move(D, a)) and b : -closure(move(D, b)) c : -closure(move(D, c)) a : -closure(move(D, a)) = -closure(move({1,2,4,5,6,8},a))} adds {3} (since move(2, a) = 3) -closure({3}) = {3} Define M(D, a) = B b : -closure(move(D, b)) = -closure(move({1,2,4,5,6,8}, b)) There is NO transition on b for all states 1,2,4,5,6, and 8 Define M(D, b) = Reject c : -closure(move(D, c)) = -closure(move({1,2,4,5,6,8},c)) adds {7} (since move(6, c) = 7) From this we have : -closure({7}) = {1,2,5,6,7,8} (since 758, 7512, and 7516 by -moves) Define M(D, c) = C

The Resulting DFA M Which States are FINAL States ? 1, 2, 5, 6, 7, 8 1, 2, 4, 5, 6, 8 0, 1, 2, 6, 8 3 c b a Which States are FINAL States ? D C A B c b a

strings over {a,b} with next-to-last symbol = a NFA-e  DFA: Example strings over {a,b} with next-to-last symbol = a a/b d a b e q0 {q0, q1} {q0}  q1 {q2} q2 a a/b q0 q1 q2 M = ({q0, q1, q2}, {a,b}, d, q0, {q2}) b q0 q1 q0 a a a a b b q0 q2 b q0 q1 q2 Equivalent DFA

An Example of NFA-e  DFA Consider a simple NFA: Construct a corresponding DFA: 1 Start q0 q1 {q0} {q0, q1} {q1} ERR Start 1 1,0

Examples See examples 2.11, 2.12, and 2.13

Class Discussion Construct a DFA equivalent to this NFA: 0,1 1 Start 1 q2 1 {q0, q1} Start 1 {q0} {q0,q2}

Class Discussion {0,1,2} {2} a {1,2} b c Converted DFA start b,c b start b,c b a,b,c An NFA a 1 2 b,c c start Notice that the state with label {0, 1, 2} is from the set of states given by the nondeterministic transition (0, a) = {0, 1, 2}. Also notice that any state whose label contains an accepting state is defined as an accepting state in the deterministic machine.

2.4 Reduction of the Number of States in FA Self study but not included in the exams material