Professional Documents
Culture Documents
Lecture 3 Deterministic Finite Automata
Lecture 3 Deterministic Finite Automata
Lecture 3 Deterministic Finite Automata
• Firstly, let’s consider how many possible strings there are over an alphabet 𝚺
• i.e. how large is 𝚺 ∗ for any alphabet 𝚺
𝜺 𝟎 𝟏 𝟎𝟎 𝟎𝟏 𝟏𝟎 𝟏𝟏 𝟎𝟎𝟎 …
1 2 3 4 5 6 7 8 …
Is the set of all languages / decision problems countable?
• Now, how large is the set of all possible languages over an alphabet 𝚺?
• So, the set of all languages over 𝚺 is the set of all subsets of 𝚺 ∗ (powerset)
𝓟(𝚺 ∗ )
• We will prove that the powerset of any countably infinite set is uncountable
• This would imply that 𝓟(𝚺 ∗ ) is uncountable
• If the barber shaves themself, then the barber doesn’t shave the barber…
• If the barber doesn’t shave themself, then the barber shaves the barber…
This is a paradox.
𝑺𝟏 = …
𝑺𝟐 = …
𝑺𝟑 = …
…
• Consider the subset 𝑫 ⊆ ℕ where 𝑫 = 𝒊 ∈ ℕ| 𝒊 ∉ 𝑺𝒊
• e.g. if 𝑺𝟏 does not contain the number 1, then 1 is in 𝑫
• e.g. if 𝑺𝟓 does not contain the number 5, then 5 is in 𝑫
• e.g. if 𝑺𝟖 contains the number 8, then 8 is not in 𝑫
𝓟(ℕ) is uncountable
…
• 𝑫 would be {𝟏, 𝟑, 𝟒, … }
• 𝟏, 𝟑, 𝟒 ∈ 𝑫 since 𝟏 ∉ 𝑺𝟏 , 𝟑 ∉ 𝑺𝟑 , and 𝟒 ∉ 𝑺𝟒
• 𝟐, 𝟓 ∉ 𝑫 since 𝟐 ∈ 𝑺𝟐 and 𝟓 ∈ 𝑺𝟓
𝓟(ℕ) is uncountable
• Consider the subset 𝑫 ⊆ ℕ where 𝑫 = 𝒊 ∈ ℕ| 𝒊 ∉ 𝑺𝒊
…
𝑺𝒋 = 𝑫 = …
Recap:
• By showing 𝓟(ℕ) is uncountable, we also have that 𝓟(𝚺 ∗ ) is uncountable
• Therefore, the set of all languages / decidable problems is uncountably infinite
What language is recognized by this finite automaton (i.e. what are all the strings
which are accepted)?
Formal Definition: Deterministic Finite Automaton
A deterministic finite automaton (DFA) is a 5-tuple (𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) where
• 𝑸 is a finite set called the states
• 𝚺 is a finite set called the alphabet
• 𝜹: 𝑸 × 𝚺 → 𝑸 is the transition function (i.e. 𝜹(𝐜𝐮𝐫𝐫_𝐬𝐭𝐚𝐭𝐞, 𝐬𝐲𝐦𝐛𝐨𝐥) = 𝐧𝐞𝐱𝐭_𝐬𝐭𝐚𝐭𝐞)
• 𝒒𝟎 ∈ 𝑸 is the start state
• 𝑭 ⊆ 𝑸 is the set of accept states
State Diagram DFA Definition
𝑞1 , 𝑞2 , 𝑞3 , 𝑞4 , 0, 1 , 𝛿, 𝑞1 , 𝑞3 with
0
𝛿: 𝑄 × Σ → 𝑄 defined by
1 𝑞2
𝑞4 0 𝜹 𝟎 𝟏 input
1 current 𝑞1 𝑞3 𝑞2 next
0 1
𝑞1 𝑞2 𝑞4 𝑞3
𝑞3 1
𝑞3 𝑞1 𝑞2
0
𝑞4 𝑞4 𝑞3
Language of a DFA
Let 𝑴 = (𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) be a DFA and 𝑨 be the set of all strings that 𝑴 accepts
• 𝑨 is called the language of machine 𝑴
𝑴 𝑞1 , 𝑞2 , 𝑞3 , 0, 1 , 𝛿, 𝑞1 , 𝑞3 with
1 𝑞2 0, 1 𝛿: 𝑄 × Σ → 𝑄 defined by
𝜹 𝟎 𝟏
𝑞1 𝑞3 0, 1 𝑞1 𝑞3 𝑞2
𝑞2 𝑞3 𝑞3
0 𝑞3 𝑞1 𝑞2
2. 𝜹 𝒓𝒊 , 𝒘𝒊+𝟏 = 𝒓𝒊+𝟏
3. 𝒓𝒏 ∈ 𝑭
𝒘𝟏 𝒘𝟐 … 𝒘𝒏
𝒘𝟏 𝒘𝟐 … 𝒘𝒏 𝒓𝟎 𝒓𝟏 𝒓𝟐 𝒓𝒏
0
𝑴
1 𝑞2
𝑞4 0
1
0 1
𝑞1
𝑞3 1
0
• 𝑞1 , 𝑞3 , 𝑞1 , 𝑞2 , 𝑞3 , 𝑞1 , 𝑞2
• 𝒘∉𝑳 𝑴
Computation of DFA – Sequence of States
• What is the sequence of states when the following DFA 𝑴 computes
𝒘 = 𝟎𝟎𝟏𝟏𝟎𝟏𝟏
0
𝑴
1 𝑞2
𝑞4 0
1
0 1
𝑞1
𝑞3 1
0
• 𝑞1 , 𝑞3 , 𝑞1 , 𝑞2 , 𝑞3 , 𝑞1 , 𝑞2 , 𝑞3
• 𝒘∈𝑳 𝑴
Regular Languages
• The set of all languages recognized by the set of all possible DFAs is
called the regular languages
Regular Languages
𝑴
1 𝑞2 0, 1
𝑞1 𝑞3 0, 1
𝑞3 0, 1
Try to write the formal DFA definition (i.e. the 5-tuple): 𝑴 = (𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) where
• 𝑄 = {𝑞3 , 𝑞4 }
• Σ = 0, 1, 2
• 𝑞0 = 𝑞3
• 𝐹 = 𝑞3
• However, in a DFA, the transition function 𝜹: 𝑸 × 𝚺 → 𝑸 must have an outgoing
transition for each alphabet symbol
• This state diagram does not correspond to a valid DFA since 𝒒𝟑 does not have an
outgoing transition for 2
DFA Example 2
Is this the state diagram for a valid DFA?
𝑞4 0, 1
𝑞3 0, 1
Note: When asked to provide a DFA, you must give the 5-tuple (the state diagram
by itself is not a formal DFA). For the transition function, unless specified, you can
provide the table or say “described by the state diagram”.
DFA Example 2
𝑴 𝑞4 0, 1
𝑞3 0, 1
• 𝑳 𝑴 = 𝜺