ch2 Engineering
ch2 Engineering
Fall 2013
Asish Mukhopadhyay
School of Computer Science
University of Windsor
Formal Definition of a DFA
• A DFA is a 5-tuple : (Q, ∑, δ, q0, F)
– Q is the set of states
– ∑ is the input alphabet
– δ is the transition function
• δ : Q X ∑ -> Q
– F , a subset of Q, is the set of final states
Example
• Q = {q0, q1}
• ∑ = {0,1}
• F = {q0}
Extended transition function
ˆ
(q, e) q
ˆ(q, aw) ˆ( (q, a), w)
Transition function Example
ˆ (q0 ,1)
ˆ ( (q ,1), )
0
ˆ (q0 , )
q0
Language accepted by a DFA
• L = { w in ∑* |ˆ (q0, w) is an accepting state of
A}
Regular Language
• Language accepted by a DFA
DFA Constructions
• Example 2
– Construct a DFA that accepts all strings over {0,1}
such that the reverse of w, when evaluated in
decimal, is divisible by 5 (or, multiple of 5)
Reverse of a string
• If w =x1x2..xk is a string, then wr = xkxk-1,…,x1
• Thus if w = 1101, wr = 1011
Main Observation
• The contribution , modulo 5, of a current 1 bit
is periodic with respect to its position from
the left.
• That’s because:
– 20 mod 5 = 1 24 mod 5 = 1
– 21 mod 5 = 2 25 mod 5 = 2 ……….
– 22 mod 5 = 4 26 mod 5 = 4
– 23 mod 5 = 3 27 mod 5 = 3
State description
• q i,j
– i is the current position in the string modulo 4
– j is the cumulative reminder modulo 5 of the
string seen so far
Transition function
• δ(qi,j, 0) = q(i+1) mod 4, j
• δ(qi,j, 1) = q(i+1) mod 4, (j +2(i+1) mod 4) mod 5
• Start state : q-1,0
DFA constructions
• Example 3
– The set of all strings such that each block of five
consecutive symbols contains at least two 0’s.
Solution
• Build a DFA, maintaining 2 pieces of
information
– The decimal value of the current block of 5 bits
– The number of 0’s in it
• Updating the decimal value as we move one
place right:
– (oldValue * 2) mod 32 + decimal value of the new
bit (this value tells us whether the leading bit of
the block of 5 bits is a 1 or a 0)
DFA for modified Example 3
Example 4
Example 4
Product automaton
• Let DFA Ai = (Qi, ∑, δi, qi0, Fi), for i = 1, 2,
recognize language Li over ∑.
• Then the automaton
– A1 X A2 = (Q1 X Q2, ∑, δ, (q01, q02 ), F1 X F2), where
δ((q1i ,q2j), a) = (δ1(q1i , a), δ2 (q2j, a)), for all a in ∑
is called the product automaton of A1 and A2
• The language accepted by A1 X A2 is the set of
all strings in L1 L2
Solving the last problem
• Now use the idea of a product automaton to
construct an automaton with 12 states that
accepts all strings the begin with and end in
01.
A DFA accepting strings beginning with
01 or ending in 01
Nondeterministic Finite Automata
• NFA, for short
• Allow transitions from a given state on a given
input to any one of a finite number of states
or no state at all
Problem
• Construct an automaton that accepts all
strings over ∑ = {0, 1} such that the tenth
(10th) symbol from the right end is a 1
Example 5
Designing a DFA
• Not straightforward
• Simpler problem
– Construct a DFA that accepts strings whose
second digit from the right is a 1
Solution
• Compute modulo 4 the decimal value of the
string seen thus far
• If the value is 2 or 3 when we come to the end
of the string the second bit from the right is 1
• Update value as we advance one place right:
– Multiply previous value by 2, add the current bit
and compute the result modulo 4
Transition table
:Q 2 Q
Extended transition function
ˆ(q, ) {q}
ˆ(q, wa) r (r , a), where r ˆ(q, w)
Language accepted by NFA
• L = {w in ∑* |ˆ (q0, w) intersection F is not
empty}
NFA to DFA reduction
• Subset construction technique
– The states of the DFA are all possible subsets of
the states of the NFA
– The start state is: {q0}
– Final states:
• All subsets that contain at least one of the accepting
states of the NFA
Construction by example (1)
Construction by example (2)
• If δD() is the transition function of the DFA,
and S is a subset of the states of the NFA then
D (S , a) q N (q, a), q S
Equivalent DFA
Transition table
Proof sketch (1)
• Let L1 be the language accepted by the given
NFA
• Let L2 be the language accepted by the
constructed DFA
• We show L1 = L2
• For this we show that ˆD ({q0},w) is an
accepting state iff ˆN (q0,w) contains an
accepting state of the given NFA.
Proof sketch (2)
• We establish the stronger fact
• Inductive hypothesis
ε-NFA for RS
Regular expressions to ε-NFAs
ε-NFA for R*
Example
• Construct ε-NFA that accepts L((0 +10)*1*))
ε-NFA for L((0 +10)*1*))
ε-NFA for L((0 +10)*1*))
Summing up (1)
• With this we have completed the sequence of
reductions
Summing up (2)
• This establishes the equivalence of all the
computational models in that they all
recognize the class of regular languages