370 likes | 1.04k Views
AUTOMATA THEORY. Reference: Introduction to Automata Theory Languages and Computation Hopcraft , Ullman and Motwani. Chapter 02. FINITE AUTOMATA. D eterministic F inite A utomata. A Deterministic Finite Automaton (DFA) is a 5-tuple ( Q , S , d , q 0 , F ) where
E N D
AUTOMATA THEORY Reference: Introduction to Automata Theory Languages and Computation Hopcraft, Ullman and Motwani
Chapter 02 FINITE AUTOMATA
Deterministic Finite Automata A Deterministic Finite Automaton (DFA) is a 5-tuple (Q, S, d, q0, F) where Q is a finite set of States S is an Alphabet, finite set of input symbol d: Q×S → Q is a Transition Function d (q, a)=p where q= present state p=next state and a=input q0ÎQ is the Initial State F ÍQ is a set of Accepting States (or Final States) will be denoted by DoubleLoops.
Notations for DFA There are two preferred notations for describing automata: A Transition Diagram A Transition Table
TRANSITION DIAGRAM For each state in Q there is a node. d(q, a)=p arc from node q to p and labeled a. There is an arrow into start state q0, labeled start. Nodes corresponding to accepting states are marked by a double circle.
Example Draw the Transition Diagram for the DFA accepting all string with a substring 01. 1 0 0,1 Start q0 0 q1 1 q2 A=({q0,q1,q2},{0,1}, d ,q0,{q2}) Check with the string 01,0111,110101,11101101
TRANSITION TABLE A transition table is a conventional, tabular representation of a function like d that takes two arguments and return a value. The rows of the table correspond to the states and return the columns correspond to the inputs. The start state is marked with an arrow and accepting states are marked with a star.
Example with Transition Table (q0,0)=q1 (q0,1)=q0 (q1,0)=q1 (q1,1)=q2 (q2,0)=q2 (q2,1)=q2 1 0 0,1 Start q0 0 q1 1 q2
TRY THIS Substring 011 Substring end with 01
How a DFA Process String The language of the DFA is the set of all strings that the DFA accepts. Suppose a1a2….an is a sequence of input symbols. We start out with the DFA in its start state q0. We consult the transition function d say d(q0,a1)=q1 to find the state that the DFA A enters after processing the first input symbol a1. We process the next input symbol a2, by evaluating d(q1,a2). Let us suppose this state is q2. we continue this manner, finding states q3,q4…qn such that d(qi-1, ai)=qi for each i. if qn is a member of F, then the input a1,a2…an is accepted, and if not then it is rejected.
Extended Transition Formula An Extended Transition Function that describes what happen when we start in any state and follow any sequence of inputs. dTransition Function d Extended Transition Function ^
dtakes a state p and a string w, and returns a state q. d(q, €)=q If are in state q and read no. of inputs then we are still in q. 2. d(q,w)=d (d(q,x),a) w xa a last symbol w string x string consisting of all but the last symbol Extended Transition Formula Extended Transition Formula ^ ^ ^ ^
Example with Transition Table w= 11011 x= 1101 a= 1 1 0 0,1 Start q0 0 q1 1 q2 ^ • d (q0, €)=q0 • d(q0,1)= d(d(q0, €),1) = d(q0,1)=q0 • d(q0,11)= d(d(q0, 1),1)= d(q0,1)=q0 • d(q0,110)=d(d(q0,11),0)= d(q0,0)=q1 • d(q0,1101)=d(d(q0,110),1)=d(q1,1)=q2 • d(q0,11011)=d(d(q0,1101),1)=d(q2,1)=q2 Accepted ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
The Language of a DFA The Language of a DFA, A=(Q, S, d, q0, F) is defined by, L(A)={w| d(q0,w) is in F} That is, the language of A is the set of strings w that take the start state q0 to one of the accepting states. If L is L(A) for some DFA, then we say L is a regular language. ^
Example Let us design a DFA to accept the language L={w | w has both an even number of 0’s and even number of 1’s}
Extended transition function of the previous example with the following input w = 110101
Like the DFA, an NFA has a finite set of states. A finite set of input symbols, one start state and a set of accepting states. It also has a transition function d. For the NFA, d is a function that takes a state and input symbol as arguments but returns a set of zero, one or more states. A Nondeterministic Finite Automaton (NFA) is a 5-tuple (Q, S, d, q0, F) Nondeterministic Finite Automata
Design an NFA An NFA accepting all strings that end in 01 0,1 Start q0 q1 q2 0 1 Fig: Transition Diagram Read Details from page -56
How an NFA Process Input Sequence 00101 An NFA accepting all strings that end in 01 0,1 q0 q1 q2 0 1 Start Fig: Transition Diagram q0 q0 q0 q0 q0 q0 q1 q1 q1 (Stuck) q2 q2 (Accepted) (Stuck) 0 1 0 0 1
Design an NFA An NFA accepting all strings that end in 01 0,1 Start q0 q1 q2 0 1 Fig: Transition Diagram The NFA can be specified formally as ({q0,q1,q2},{0,1}, d ,q0,{q2}) Fig: Transition Table
Extended Transition Function Basis: d(q0, €) = {q} Induction: Suppose w=xa d(q ,x)= {p1,p2,p3………pn} Let Ud(p ,a)= {r1,r2,r3,…………rm} Then d(q ,w)= {r1,r2,r3………rm} ^ ^ k i i=1 ^
^d Processing of input 00101 by the NFA d(q0, €) = {q0} d(q0,0)= d (q0,0)= {q0,q1} d(q0,00)= d (q0,0) Ud(q1, 0)= {q0,q1} U Ø ={q0,q1} d(q0,001)=d (q0,1)Ud(q1,1)= {q0} U {q2} ={q0,q2} d(q0,0010)=d(q0,0) Ud(q2,0) = {q0,q1} UØ = {q0,q1} d(q0,00101)=d(q1,1) Ud(q0,1)={q0} U{q2}={q0,q2} Accepted 0,1 Start q0 q1 q2 0 1 ^ ^ ^ ^ ^ ^
The language of NFA An NFA accepts a string w if it is possible to make any sequence of choice of next state, while reading the characters of w, and go from start state to any accepting states If A= (Q, S, d, q0, F) is an NFA, then L(A)={w| d(q0,w)∩F ≠Ø} That is L(A) is the set of strings w in S* such that d(q0,w) contains at least one accepting stat. ^ ^
Equivalence of DFA and NFA There are many language for which an NFA is easier than a DFA. Every language that can be describe by some NFA can also be described by some DFA. In the worst case the smallest DFA can have 2 states while the smallest NFA for the same language has n states. n
0,1 Start q 0 q1 q 2 0 1
0,1 Start q0 q1 q2 0 1
0,1 Start q0 q1 q2 0 1
From the 8 states in fig starting in the start state B, we can only reach states B,E and F. The other five states are inaccessible from the start state. The DFA constructed from the fig as… 1 0 Start B E F 0 1 0 1
1 0 Start {q0} {q0,q1} {q0,q2} 0 1 0 1
Theorem 2.11,2.12 (Self) Exercise 2.3.1,2.3.2,2.3.3 (Self) 2.2.3,2.2.4,2.2.5,2.2.6,2.2.10,2.2.11(Self)