Chapter 2 - DFA
Chapter 2 - DFA
Chapter 2 - DFA
(Theory of Computation)
Chapter 2: Finite State Automata
Part 1 - DFA
Dr. Maroun Abi Assaf
1
Chapter 2 Finite State Automata
•Types of Finite State
Automata
• Deterministic automata (DFA): each move is uniquely determined.
Nondeterministic automata (NFA): the moves are not uniquely determined.
• An automata is called an accepter if its output response is limited to “yes” or “no”.
• An automata is called a transducer if it is capable of producing strings of symbols
as output.
2.1 Deterministic Finite State Automata
• Rule 1: At every state, there should be a transition for every
character of the alphabet
•Give two FSA examples (deter vs non-deter) with alphabet {a,b}
•Rule 2: At every state, there should not be two transitions with the
same character.
•Give two FSA examples (deter vs non-deter) with alphabet {a,b}
q0 q1 q2 0
1
1
Initial state Final state
Example 2.1
The above transition graph represents the dfa
M ({q0 , q1 , q2 },{0,1},δ , q0 , {q1}),
where δ is given by It accepts 01, 101,0111,11001,….
δ (q0 ,0) q0, δ (q0 ,1) q1,
But not 00, 100,1100,….
δ (q1 ,0) q0, δ (q1 ,1) q2,
δ (q2 ,0) q2, δ (q2 ,0) q1,
To accept a string: all the input string is scanned and the last state is accepting
To reject a string: all the input string is scanned and the last state is non-
accepting
Definition 2.2
The language accepted by
a dfa M (Q,, , q0 F ) is
the set of all string on Σ
accepted by M. In formal notation,
L(M) {w * : * (q0 , w) F}.
Let w a1a2 an .
If (q1 , a1 ) q2 , (q2 , a2 ) q3 , , (qn , an ) qn 1 ,
then we write δ * (q1,w) qn 1.
Especially,δ * (q,ε ) q.
Example 2.2 Consider the dfa in the following transition graph.
What is the accepted language?
a
q0 q1 q2 a,b
b a,b
Solution: Trap state
L {a nb: n 0}
Example 2.3 Find a dfa that recognizes the set of all strings
on {a, b} starting with the prefix ab.
Solution:
q0 a q1 b q2 a,b
b Trap state
q3 a,b
Example 2.4 Find a dfa that recognizes the set of all strings
on {0,1}, except those containing the substring 001.
1 0 0,1
1
ε
0 1 001
0 00
0
1 0 0,1
1
or
q0 q1 0 q2 1 q3
0
Definition 2.3 A language L is called regular if and only if there
exists some deterministic finite accepter M such that L = L(M).
Example 2.5 b a
Show that language L={awa: w {a, b}* is regular.
a
q0 q2 a q3
b
b
a,b
Example 2.6 q1
Let L be the language in Example 2.5. Show that L {aw1aaw2 a} is regular.
2
b a b a
a
q0 q2 a q3 a
q4 a q5
b b
b
a,b
q1
Example 2.6 Given the following DFA:
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
a a, b
q0 b q1 a, b q2