2 Deterministic Finite Automata
2 Deterministic Finite Automata
1
Deterministic Finite Automata
(DFA)
• In DFA, given current state, we know what
next state will be
• In other words, the exact state to which the
machine moves can be determined.
• It has only one unique state, no choices and
randomness 1
–A B
𝑄 : set of states
Σ : input alphabet 𝜆∉Σ
𝛿 : transition function
𝑞 0 : initial state
𝐹 : set of accepting states
3
Deterministic Finite Automaton (DFA)
Input Tape
String
Output
“Accept”
Finite or
Automaton “Reject”
4
Transition Graph
𝑄= {𝑞 0 ,𝑞 1 ,𝑞 2 , 𝑞 3 , 𝑞 4 , 𝑞5 }
𝑎,𝑏
Σ ={ 𝑎 , 𝑏 }
𝑞5
𝑏
𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
initial accepting
state state
transition
state
5
Simulator to try other Examples
at Home: jFAST
jFAST is a simple finite automata (FA)
graphical simulation utility; it is
designed to feature simple mechanisms
for creating, editing, and simulating FA.
jFAST is ideal for use by students,
instructors, and self-guided explorers
alike.
https://sourceforge.net/projects/jfast-fsm
-sim/
Example
Σ ={ 𝑎 ,𝑏 } 𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
8
Initial State 𝑞 0
Example
𝑎,𝑏
𝑞5
𝑏
𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
9
Set of Accepting States 𝐹 ⊆𝑄
Example
𝐹 = { 𝑞4 } 𝑎,𝑏
𝑞5
𝑏
𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
10
Transition Function 𝛿: 𝑄 × Σ→ 𝑄
′
𝛿(𝑞 , 𝑥)=𝑞
𝑥 ′
𝑞 𝑞
11
Example:
𝛿 ( 𝑞0 , 𝑎 )=𝑞 1
𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
12
𝛿 ( 𝑞0 , 𝑏 ) =𝑞5
𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
13
𝛿 ( 𝑞2 , 𝑏 ) =𝑞3
𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
14
Transition Table for 𝛿
symbols
𝛿 𝑎 𝑏
𝑞0 𝑞1 𝑞5
𝑞1 𝑞5 𝑞2
states
𝑞2 𝑞5 𝑞3
𝑎,𝑏
𝑞3 𝑞4 𝑞5
𝑞4 𝑞5 𝑞5
𝑞5
𝑞5 𝑞5 𝑞5 𝑎,𝑏
𝑏 𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
15
Extended Transition Function
∗ ∗
𝛿 :𝑄 × Σ → 𝑄
∗ ′
𝛿 (𝑞 ,𝑤)=𝑞
16
∗
Example: 𝛿 ( 𝑞 0 ,𝑎𝑏 ) =𝑞 2
𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
17
∗
𝛿 ( 𝑞 0 ,𝑎𝑏𝑏𝑏𝑎𝑎 ) =𝑞5
𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
18
∗
𝛿 ( 𝑞 1 , 𝑏𝑏𝑎 ) =𝑞 4
𝑎,𝑏
𝑞5
𝑏 𝑎,𝑏
𝑎 𝑎 𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞 2 𝑏 𝑞 3 𝑎 𝑞4
19
Special case:
∗
𝛿 ( 𝑞, 𝜆 ) =𝑞
20
∗ ′
In general: 𝛿 ( 𝑞, 𝑤 )=𝑞
implies that there is a walk of transitions
𝑤=𝜎 1 𝜎 2 ⋯ 𝜎 𝑘
𝜎1 𝜎2 𝜎𝑘
′
𝑞 𝑞
states may be repeated
𝑤 ′
𝑞 𝑞
21
Language Accepted by DFA
Language L accepted by DFA machine M
is denoted as 𝐿 ( 𝑀 ) and contains all the strings
accepted by
𝑀
We also say that 𝑀 recognizes𝐿 ( 𝑀 )
𝑀 =( 𝑄 , Σ , 𝛿 ,𝑞 0 , 𝐹 )
22
For a DFA 𝑀 =( 𝑄 , Σ , 𝛿 ,𝑞 0 , 𝐹 )
𝑀
Language accepted by :
𝐿 ( 𝑀 ) = {𝑤 ∈ Σ : 𝛿 ( 𝑞 0 , 𝑤 ) ∈ 𝐹 }
∗ ∗
𝑤
𝑞0 ′
𝑞 ′
𝑞 ∈𝐹
23
Language rejected by𝑀 :
𝐿 ( 𝑀 ) = {𝑤 ∈ Σ : 𝛿 ( 𝑞 0 , 𝑤 ) ∉ 𝐹 }
∗ ∗
𝑤
𝑞0 𝑞
′ ′
𝑞 ∉𝐹
24
DFA Examples
Σ={𝑎, 𝑏}
𝑎,𝑏
𝑎,𝑏
𝑞0 𝑞0
∗
𝐿(𝑀)={} 𝐿(𝑀)=Σ
Empty language All strings
25
Σ={𝑎, 𝑏}
𝐿 ( 𝑀=) { all strings with prefix 𝑎𝑏 }
𝑎,𝑏
𝑞0 𝑎 𝑞1 𝑏 𝑞2
𝑏 𝑎 accept
𝑞3 𝑎,𝑏
26
𝐿 ( 𝑀=
) { all binary strings containing
substring 001 }
1 0
0 ,1
𝜆 0 1
0 00 001
27
𝐿(𝑀)={ 𝑎𝑤𝑎:𝑤 ∈ { 𝑎 ,𝑏 } }
∗
𝑎
𝑏
𝑞0 𝑎 𝑞2 𝑞3
𝑏 𝑎
𝑞4
𝑎,𝑏
28