Lecture 5 NFA Equivalence
Lecture 5 NFA Equivalence
1 𝑞2 0, 1 1 𝑞2 0, 1
𝑞1 𝑞3 0, 1 𝑞1 𝑞3 0, 1
• Identical state
0 0 diagram
DFA 𝑴 NFA 𝑴′
𝑞1 , 𝑞2 , 𝑞3 , 0, 1 , 𝛿, 𝑞1 , 𝑞3 with 𝑞1 , 𝑞2 , 𝑞3 , 0, 1 , 𝛿, 𝑞1 , 𝑞3 with
𝛿: 𝑄 × Σ → 𝑄 defined by 𝛿: 𝑄 × Σ ∪ 𝜀 → 𝒫(𝑄) defined by
𝜹 𝟎 𝟏 𝜹 𝟎 𝟏 𝜺
𝑞1 𝑞3 𝑞2 𝑞1 {𝑞3 } {𝑞2 } ∅ • Next states are
𝑞2 𝑞3 𝑞3 𝑞2 {𝑞3 } {𝑞3 } ∅ singleton sets
𝑞3 𝑞3 𝑞3 𝑞3 {𝑞3 } {𝑞3 } ∅ • No 𝜀 transitions
NFAs and DFAs
𝑞4 0, 1, 2
𝑞3 0, 1
• Recall, we claimed that the computational power of DFAs and NFAs are equal
• So, we will also prove that for every NFA there also exists an equivalent DFA
Equivalence of NFAs and DFAs
First: We show that for every DFA, there exists an equivalent NFA
Proof: (easy)
Let 𝑫 = (𝑸𝑫, 𝚺, 𝜹𝑫, 𝒒𝑫, 𝑭𝑫) be a DFA.
We can build NFA 𝑵 = 𝑸𝑵 , 𝚺, 𝜹𝑵 , 𝒒𝑵 , 𝑭𝑵 with 𝑳 𝑫 = 𝑳 𝑵 as follows:
• 𝑸𝑵 ≔ 𝑸𝑫
• 𝑭𝑵 ≔ 𝑭𝑫
{𝑞0, 𝑞1, 𝑞2} • 𝑸𝑫 ≔ 𝓟 𝑸𝑵 New states are all possible subsets of states in NFA
• 𝒒𝑫 ≔ {𝒒𝑵} Start state is the singleton set containing NFA start state
• 𝜹𝑫 𝑺, 𝒂 ≔ {𝒒 ∈ 𝑸𝑵 ∣ 𝒒 ∈ 𝜹𝑵 𝒔, 𝒂 for some 𝒔 ∈ 𝑺}
• Modify 𝑫 as follows:
• 𝒒𝑫 ≔ 𝑬 𝒒𝑵 Start state is 𝐸() of start state in NFA
• 𝜹𝑫 𝑺, 𝒂 ≔ {𝒒 ∈ 𝑸𝑵 ∣ 𝒒 ∈ 𝑬 𝜹𝑵 𝒔, 𝒂 for some 𝒔 ∈ 𝑺}
{𝑞0 , 𝑞1 }
1 {𝑞0, 𝑞1, 𝑞2}
NFA to DFA Example
𝑵 1 𝑞2 0
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 }
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 }
1
Transition table for DFA 𝑫 0
𝜹𝑫 𝟎 𝟏 1
∅ ∅ ∅ {𝑞1 , 𝑞3 } {𝑞1, 𝑞2, 𝑞3} 0,1
0
𝑞1 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞2 0 1 ∅
𝑞3
𝑞1 , 𝑞2
𝑞1 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞2 , 𝑞3 𝜹𝑫 𝑺, 𝒂 ≔ {𝒒 ∈ 𝑸𝑵 ∣ 𝒒 ∈ 𝑬 𝜹𝑵 𝒔, 𝒂 for some 𝒔 ∈ 𝑺}
𝑞1 , 𝑞2 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
NFA to DFA Example
𝑵 1 𝑞2 0
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 }
1
Transition table for DFA 𝑫 0
𝜹𝑫 𝟎 𝟏 1
{𝑞1 , 𝑞3 } {𝑞1, 𝑞2, 𝑞3} 0,1 {𝑞2 }
0 {𝑞3 }
∅ ∅ ∅
0
𝑞1 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞2 𝑞3 0 1 ∅
𝑞3
𝑞1 , 𝑞2
𝑞1 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞2 , 𝑞3 𝜹𝑫 𝑺, 𝒂 ≔ {𝒒 ∈ 𝑸𝑵 ∣ 𝒒 ∈ 𝑬 𝜹𝑵 𝒔, 𝒂 for some 𝒔 ∈ 𝑺}
𝑞1 , 𝑞2 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
NFA to DFA Example
𝑵 1 𝑞2 0
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 }
1
Transition table for DFA 𝑫 0
𝜹𝑫 𝟎 𝟏 1
{𝑞1 , 𝑞3 } {𝑞1, 𝑞2, 𝑞3} 0,1 {𝑞2 }
0 {𝑞3 }
∅ ∅ ∅
0
𝑞1 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
1
𝑞2 𝑞3 ∅ 0 1 ∅
𝑞3
𝑞1 , 𝑞2
𝑞1 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞2 , 𝑞3 𝜹𝑫 𝑺, 𝒂 ≔ {𝒒 ∈ 𝑸𝑵 ∣ 𝒒 ∈ 𝑬 𝜹𝑵 𝒔, 𝒂 for some 𝒔 ∈ 𝑺}
𝑞1 , 𝑞2 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
NFA to DFA Example
𝑵 1 𝑞2 0
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 } {𝑞2 , 𝑞3 }
1
Transition table for DFA 𝑫 0 0,1
𝜹𝑫 𝟎 𝟏 1
{𝑞1 , 𝑞3 } {𝑞1, 𝑞2, 𝑞3} 0,1 {𝑞2 }
0 {𝑞3 }
∅ ∅ ∅
0
𝑞1 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
0 1 1
𝑞2 𝑞3 ∅ 0 {𝑞1 , 𝑞2 } 1 ∅ 0,1
𝑞3 𝑞3 𝑞3
𝑞1 , 𝑞2 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞1 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝑞2 , 𝑞3 𝑞3 𝑞3
𝑞1 , 𝑞2 , 𝑞3 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
NFA to DFA Example
𝑵 1 𝑞2 0
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 } {𝑞2 , 𝑞3 }
1
Transition table for DFA 𝑫 0 0,1
𝜹𝑫 𝟎 𝟏 1
{𝑞1 , 𝑞3 } {𝑞1, 𝑞2, 𝑞3} 0,1 {𝑞2 }
0 {𝑞3 }
∅ ∅ ∅
0
𝒒𝟏 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
0 1 1
𝑞2 𝑞3 ∅ 0 {𝑞1 , 𝑞2 } 1 ∅ 0,1
𝒒𝟑 𝑞3 𝑞3
𝒒𝟏 , 𝒒𝟐 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝒒𝟏 , 𝒒𝟑 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝒒𝟐 , 𝒒𝟑 𝑞3 𝑞3 𝑭𝑫 ≔ {𝑺 ∈ 𝑸𝑫 ∣ there exists a 𝒒 ∈ 𝑺 with 𝒒 ∈ 𝑭𝑵 }
𝒒𝟏 , 𝒒𝟐 , 𝒒𝟑 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
NFA to DFA Example
𝑵 1 𝑞2 0
𝑞1 𝑞3
𝑫
𝜀
0,1 0,1
{𝑞1 } {𝑞2 , 𝑞3 }
1
Transition table for DFA 𝑫 0 0,1
𝜹𝑫 𝟎 𝟏 1
{𝑞1 , 𝑞3 } {𝑞1 , 𝑞2 , 𝑞3 } 0,1 {𝑞2 }
0 {𝑞3 }
∅ ∅ ∅
0
𝒒𝟏 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
0 1 1
𝑞2 𝑞3 ∅ 0 {𝑞1 , 𝑞2 } 1 ∅ 0,1
𝒒𝟑 𝑞3 𝑞3
𝒒𝟏 , 𝒒𝟐 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝒒𝟏 , 𝒒𝟑 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
𝒒𝟐 , 𝒒𝟑 𝑞3 𝑞3
𝒒𝟏 , 𝒒𝟐 , 𝒒𝟑 𝑞1 , 𝑞3 𝑞1 , 𝑞2 , 𝑞3
Equivalence of NFAs and DFAs
• So, we know that DFAs and NFAs produce the same set of languages
Theorem: If 𝑳𝟏 and 𝑳𝟐 are regular languages over alphabet Σ, then the language
𝑳𝟏 𝑳𝟐 is a regular language
Proof: Since 𝑳𝟏 and 𝑳𝟐 are regular languages, then there exist DFAs 𝑴𝟏 and 𝑴𝟐
where 𝑳𝟏 = 𝑳(𝑴𝟏 ) and 𝑳𝟐 = 𝑳(𝑴𝟐 )
We can create an NFA 𝑴 that accepts the strings where the first part is accepted
by 𝑴𝟏 and the second part is accepted by 𝑴𝟐 .
Regular Languages are Closed under Concatenation
𝑴𝟏 = 𝑸𝟏 , 𝚺, 𝜹𝟏 , 𝒒𝟏 , 𝑭𝟏 𝑴𝟐 = 𝑸𝟐 , 𝚺, 𝜹𝟐 , 𝒒𝟐 , 𝑭𝟐
𝑓1 𝑓4
𝑴 𝑞1 𝑓2 𝑞2 𝑓5
𝑓3 𝑓6
𝑓1 𝑓4
𝑴 𝑞1 𝑓2 𝑞2 𝑓5
𝑓3 𝑓6
𝑓1 𝑓4
𝑴 𝑞1 𝑓2 𝑞2 𝑓5
𝑓3 𝑓6
𝑓1 𝜺 𝑓4
𝑓2 𝜺 𝑓5
𝑴 𝑞1
𝜺
𝑞2
𝑓3 𝑓6
• 𝑳𝟏 ∪ 𝑳𝟐 is a regular language
• 𝑳𝟏 ∩ 𝑳𝟐 is a regular language
• 𝑳𝟏 𝑳𝟐 is a regular language
Regular languages are also closed under complement and Kleene star:
• 𝑳𝟏 is a regular language