Lecture 4 Closure and NFAs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Lecture 4: Closure and NFAs

CSC 320: Foundations of Computer Science


Quinton Yong
quintonyong@uvic.ca
Closure Properties for Sets

• A set is closed under some operation if applying the operation to


elements of the set returns another element of the set

• Example: The set of even numbers is closed under addition since


adding even numbers returns another even number
Closure Properties for Language Classes

• We can also have closure properties for classes of languages (e.g. regular
languages)

• That is, if we apply a set operation to languages in a certain class, the


resulting language is also in that class

• We will prove that performing the union, intersection, and concatenation


of two regular languages 𝑳𝟏 and 𝑳𝟐 results in another regular language

• i.e. Regular languages are closed under union, intersection, and


concatenation
Regular Languages are Closed under Union

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 𝑳𝟐 = 𝑳(𝑴𝟐 )

Proof idea: Construct a DFA 𝑴 that accepts exactly the strings accepted by 𝑴𝟏 as
well as the strings accepted by 𝑴𝟐

We do this by creating a DFA which simulates both machines concurrently, and


accepts if at least one of them accepts
Regular Languages are Closed under Union

Example: Σ = 0, 1
• 𝑳𝟏 : set of strings that, after a possible prefix of 1s, consists of at least one 0
followed by at least one symbol

1 0, 1
𝑴1
𝑞1 0 𝑝𝑎 0, 1
𝑝𝑏

• 𝑳𝟐 : set of all strings of length exactly 1

0, 1
𝑴2
𝑞2 0, 1 0, 1 𝑠𝑏
𝑠𝑎
Regular Languages are Closed under Union
1 0, 1 0, 1
𝑴1 𝑴2
𝑞1 0 𝑝𝑎 0, 1 𝑞2 0, 1 0, 1 𝑠𝑏
𝑝𝑏 𝑠𝑎

Union idea for 𝑴:


• Use pairs of states of 𝑴𝟏 and 𝑴𝟐 as states in 𝑴

0 𝑝𝑎 , 𝑠𝑎

𝑞1 , 𝑞2

1 𝑞1 , 𝑠𝑎

• Transitions for a symbol 𝒂 ∈ 𝚺 is the state pair corresponding to where 𝑴𝟏 goes


with 𝒂 and where 𝑴𝟐 goes with 𝒂 (simulate both DFAs)

• State is an accept state if either resulting state in 𝑴𝟏 or 𝑴𝟐 is an accept state


Regular Languages are Closed under Union
Proof continued:
Let 𝑴𝟏 = 𝑸𝟏 , 𝚺, 𝜹𝟏 , 𝒒𝟏 , 𝑭𝟏 and 𝑴𝟐 = 𝑸𝟐 , 𝚺, 𝜹𝟐 , 𝒒𝟐 , 𝑭𝟐 be DFAs.
We construct DFA 𝑴 = 𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭 as follows:
• 𝑸= 𝒓𝟏 , 𝒓𝟐 | 𝒓𝟏 ∈ 𝑸𝟏 , 𝒓𝟐 ∈ 𝑸𝟐 ,
• all pairs of states where one is from 𝑴𝟏 and one is from 𝑴𝟐

• For each 𝒓𝟏 , 𝒓𝟐 ∈ 𝑸 and each 𝒂 ∈ 𝚺 define transition function


𝜹 ∶ 𝜹 𝒓𝟏 , 𝒓𝟐 , 𝒂 = 𝜹𝟏 𝒓𝟏 , 𝒂 , 𝜹𝟐 𝒓𝟐 , 𝒂

• 𝒒𝟎 = (𝒒𝟏 , 𝒒𝟐 )
• Start from the state pair with starts states of 𝑴𝟏 and 𝑴𝟐

• 𝑭= 𝒓𝟏 , 𝒓𝟐 | 𝒓𝟏 ∈ 𝑭𝟏 or 𝒓𝟐 ∈ 𝑭𝟐
• Strings are accepted if at least one DFA accepts
𝑴 recognizes 𝑳𝟏 ∪ 𝑳𝟐
Regular Languages are Closed under Union
• Same example as before (fully worked out):
1 0, 1 0, 1
𝑴1 𝑴2
𝑞1 0 𝑝𝑎 0, 1 𝑞2 0, 1 0, 1 𝑠𝑏
𝑝𝑏 𝑠𝑎

Transition table for 𝑴


• For each 𝒓𝟏 , 𝒓𝟐 ∈ 𝑸 and each 𝒂 ∈ 𝚺 define transition function
𝑸 𝟎 𝟏
𝜹 ∶ 𝜹 𝒓𝟏 , 𝒓𝟐 , 𝒂 = 𝜹𝟏 𝒓𝟏 , 𝒂 , 𝜹𝟐 𝒓𝟐 , 𝒂
𝑞1 , 𝑞2 (𝑝𝑎 , 𝑠𝑎 ) (𝑞1 , 𝑠𝑎 )
𝑞1 , 𝑠𝑎 (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
(𝑞1 , 𝑠𝑏 ) (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
(𝑝𝑎 , 𝑞2 )
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏 (𝑝𝑎 , 𝑠𝑎 )
0 0 0 (𝑝𝑎 , 𝑠𝑏 )
𝑞1 , 𝑞2
1 𝑞1 , 𝑠𝑎
1 𝑞1 , 𝑠𝑏
1 (𝑝𝑏 , 𝑞2 )
(𝑝𝑏 , 𝑠𝑎 )
(𝑝𝑏 , 𝑠𝑏 )
Regular Languages are Closed under Union
• Same example as before (fully worked out):
1 0, 1 0, 1
𝑴1 𝑴2
𝑞1 0 𝑝𝑎 0, 1 𝑞2 0, 1 0, 1 𝑠𝑏
𝑝𝑏 𝑠𝑎

Transition table for 𝑴


𝑸 𝟎 𝟏
𝑝𝑏 , 𝑠𝑎 𝑞1 , 𝑞2 (𝑝𝑎 , 𝑠𝑎 ) (𝑞1 , 𝑠𝑎 )
0, 1 0, 1 𝑞1 , 𝑠𝑎 (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
0, 1
0, 1 (𝑞1 , 𝑠𝑏 ) (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏
(𝑝𝑎 , 𝑞2 ) (𝑝𝑏 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑎 )
0, 1 0, 1 (𝑝𝑎 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
(𝑝𝑎 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0 (𝑝𝑏 , 𝑞2 ) (𝑝𝑏 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑎 )
1 1 1 (𝑝𝑏 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
𝑞1 , 𝑞2 𝑞1 , 𝑠𝑎 𝑞1 , 𝑠𝑏
(𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
Regular Languages are Closed under Union
• Same example as before (fully worked out):
1 0, 1 0, 1
𝑴1 𝑴2
𝑞1 0 𝑝𝑎 0, 1 𝑞2 0, 1 0, 1 𝑠𝑏
𝑝𝑏 𝑠𝑎

Transition table for 𝑴


• 𝑭= 𝒓𝟏 , 𝒓𝟐 | 𝒓𝟏 ∈ 𝑭𝟏 or 𝒓𝟐 ∈ 𝑭
𝑸 𝟎 𝟏
𝑝𝑏 , 𝑠𝑎
𝑞1 , 𝑞2 (𝒑𝒂 , 𝒔𝒂 ) (𝒒𝟏 , 𝒔𝒂 )
0, 1 0, 1 𝒒𝟏 , 𝒔𝒂 (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
0, 1
0, 1 (𝑞1 , 𝑠𝑏 ) (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏
(𝑝𝑎 , 𝑞2 ) (𝒑𝒃 , 𝒔𝒂 ) (𝒑𝒃 , 𝒔𝒂 )
0, 1 0, 1 Accept states (𝒑𝒂 , 𝒔𝒂 ) (𝒑𝒃 , 𝒔𝒃 ) (𝒑𝒃 , 𝒔𝒃 )
(𝑝𝑎 , 𝑠𝑏 ) (𝒑𝒃 , 𝒔𝒃 ) (𝒑𝒃 , 𝒔𝒃 )
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0 (𝒑𝒃 , 𝒒𝟐 ) (𝒑𝒃 , 𝒔𝒂 ) (𝒑𝒃 , 𝒔𝒂 )
1 1 1 (𝒑𝒃 , 𝒔𝒂 ) (𝒑𝒃 , 𝒔𝒃 ) (𝒑𝒃 , 𝒔𝒃 )
𝑞1 , 𝑞2 𝑞1 , 𝑠𝑎 𝑞1 , 𝑠𝑏
(𝒑𝒃 , 𝒔𝒃 ) (𝒑𝒃 , 𝒔𝒃 ) (𝒑𝒃 , 𝒔𝒃 )
Regular Languages are Closed under Union

𝑳 𝑴 = 𝑳𝟏 ∪ 𝑳𝟐
Transition table for 𝑴
𝑝𝑏 , 𝑠𝑎 𝑸 𝟎 𝟏
0, 1 0, 1 𝑞1 , 𝑞2 (𝑝𝑎 , 𝑠𝑎 ) (𝑞1 , 𝑠𝑎 )
0, 1 𝑞1 , 𝑠𝑎 (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
0, 1
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏 (𝑞1 , 𝑠𝑏 ) (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
0, 1 0, 1 (𝑝𝑎 , 𝑞2 ) (𝑝𝑏 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑎 )
(𝑝𝑎 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
𝑴 𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0 (𝑝𝑎 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
(𝑝𝑏 , 𝑞2 ) (𝑝𝑏 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑎 )
𝑞1 , 𝑞2
1 𝑞1 , 𝑠𝑎
1 𝑞1 , 𝑠𝑏
1
(𝑝𝑏 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
(𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
Regular Languages are Closed under Union
Recall:
• 𝑳𝟏 : set of strings that, after a possible prefix of 1s, consists of at least one 0
followed by at least one symbol
• 𝑳𝟐 : set of all strings of length exactly 1

• Verify that 0 ∈ 𝑳𝟏 ∪ 𝑳𝟐 and also 11100 ∈ 𝑳𝟏 ∪ 𝑳𝟐 are accepted by 𝑴

𝑝𝑏 , 𝑠𝑎

0, 1 0, 1
0, 1
0, 1
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏

0, 1 0, 1
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0

𝑞1 , 𝑞2
1 𝑞1 , 𝑠𝑎
1 𝑞1 , 𝑠𝑏
1
Regular Languages are Closed under Union
Recall:
• 𝑳𝟏 : set of strings that, after a possible prefix of 1s, consists of at least one 0
followed by at least one symbol
• 𝑳𝟐 : set of all strings of length exactly 1

• Verify that 0 ∈ 𝑳𝟏 ∪ 𝑳𝟐 and also 11100 ∈ 𝑳𝟏 ∪ 𝑳𝟐 are accepted by 𝑴

𝑝𝑏 , 𝑠𝑎

0, 1 0, 1
0, 1
0, 1
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏

0, 1 0, 1
0
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0

𝑞1 , 𝑞2
1 𝑞1 , 𝑠𝑎
1 𝑞1 , 𝑠𝑏
1
Regular Languages are Closed under Union
Recall:
• 𝑳𝟏 : set of strings that, after a possible prefix of 1s, consists of at least one 0
followed by at least one symbol
• 𝑳𝟐 : set of all strings of length exactly 1

• Verify that 0 ∈ 𝑳𝟏 ∪ 𝑳𝟐 and also 11100 ∈ 𝑳𝟏 ∪ 𝑳𝟐 are accepted by 𝑴

𝑝𝑏 , 𝑠𝑎

0, 1 0, 1
0, 1
0, 1
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏

0, 1 0, 1
11100
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0

𝑞1 , 𝑞2
1 𝑞1 , 𝑠𝑎
1 𝑞1 , 𝑠𝑏
1
Regular Languages are Closed under Intersection

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 𝑳𝟐 = 𝑳(𝑴𝟐 )

Proof idea: We can create a DFA which simulates both machines concurrently
in the exact same way as the union closure proof.

However, now the strings that are accepted by the new DFA are the strings which
are accepted by both 𝑴𝟏 and 𝑴𝟐 (instead of either one)
Regular Languages are Closed under Intersection
Proof continued:
Let 𝑴𝟏 = 𝑸𝟏 , 𝚺, 𝜹𝟏 , 𝒒𝟏 , 𝑭𝟏 and 𝑴𝟐 = 𝑸𝟐 , 𝚺, 𝜹𝟐 , 𝒒𝟐 , 𝑭𝟐 be DFAs.
We construct DFA 𝑴 = 𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭 as follows:
• 𝑸= 𝒓𝟏 , 𝒓𝟐 | 𝒓𝟏 ∈ 𝑸𝟏 , 𝒓𝟐 ∈ 𝑸𝟐 ,

• For each 𝒓𝟏 , 𝒓𝟐 ∈ 𝑸 and each 𝒂 ∈ 𝚺 define transition function


𝜹 ∶ 𝜹 𝒓𝟏 , 𝒓𝟐 , 𝒂 = 𝜹𝟏 𝒓𝟏 , 𝒂 , 𝜹𝟐 𝒓𝟐 , 𝒂

• 𝒒𝟎 = (𝒒𝟏 , 𝒒𝟐 )
The DFA construction is exactly the same
• 𝑭= 𝒓𝟏 , 𝒓𝟐 | 𝒓𝟏 ∈ 𝑭𝟏 𝐚𝐧𝐝 𝒓𝟐 ∈ 𝑭𝟐 as before, except for which states we
make accept states

𝑴 recognizes 𝑳𝟏 ∩ 𝑳𝟐
Regular Languages are Closed under Intersection
• 𝑳 𝑴 = 𝑳𝟏 ∩ 𝑳𝟐 (where 𝑳𝟏 and 𝑳𝟐 are same as union closure example)
1 0, 1 0, 1
𝑴1 𝑴2
𝑞1 0 𝑝𝑎 0, 1 𝑞2 0, 1 0, 1 𝑠𝑏
𝑝𝑏 𝑠𝑎

Transition table for 𝑴


• 𝑭= 𝒓𝟏 , 𝒓𝟐 | 𝒓𝟏 ∈ 𝑭𝟏 𝐚𝐧𝐝 𝒓𝟐 ∈ 𝑭𝟐
𝑸 𝟎 𝟏
𝑝𝑏 , 𝑠𝑎
𝑞1 , 𝑞2 (𝑝𝑎 , 𝑠𝑎 ) (𝑞1 , 𝑠𝑎 )
0, 1 0, 1 𝑞1 , 𝑠𝑎 (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
0, 1
0, 1 (𝑞1 , 𝑠𝑏 ) (𝑝𝑎 , 𝑠𝑏 ) (𝑞1 , 𝑠𝑏 )
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏
(𝑝𝑎 , 𝑞2 ) (𝒑𝒃 , 𝒔𝒂 ) (𝒑𝒃 , 𝒔𝒂 )
0, 1 0, 1 Accept states (𝑝𝑎 , 𝑠𝑎 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
(𝑝𝑎 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0 (𝑝𝑏 , 𝑞2 ) (𝒑𝒃 , 𝒔𝒂 ) (𝒑𝒃 , 𝒔𝒂 )
1 1 1 (𝒑𝒃 , 𝒔𝒂 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
𝑞1 , 𝑞2 𝑞1 , 𝑠𝑎 𝑞1 , 𝑠𝑏
(𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 ) (𝑝𝑏 , 𝑠𝑏 )
Regular Languages are Closed under Intersection
• 𝑳𝟏 : set of strings that, after a possible prefix of 1s, consists of at least one 0
followed by at least one symbol
• 𝑳𝟐 : set of all strings of length exactly 1

• Notice that the strings in 𝑳𝟏 all have length at least 2 and the strings in 𝑳𝟐 have
length exactly 1, so the 𝑳𝟏 ∩ 𝑳𝟐 = ∅
The only accept state
𝑝𝑏 , 𝑠𝑎
is unreachable
0, 1 0, 1
0, 1
0, 1
𝑝𝑎 , 𝑞2 𝑝𝑏 , 𝑞2 𝑝𝑏 , 𝑠𝑏

0, 1 0, 1
𝑝𝑎 , 𝑠𝑎 𝑝𝑎 , 𝑠𝑏
0 0 0

𝑞1 , 𝑞2
1 𝑞1 , 𝑠𝑎
1 𝑞1 , 𝑠𝑏
1
Regular Languages are Closed under Concatenation

• How do we create a DFA which accepts the concatenation of two regular


languages?

• We will introduce a different computational model which makes this easier but
has the same computational power as a DFA
Deterministic Computation

Computation on a DFA is deterministic


• When computing a string, there is no ambiguity (deterministic) for the
current state is and the next state when reading a character
• Single execution path for every string
1 0, 1
0 0, 1
Nondeterministic Computation

We describe another computational model with the same computational power


as a DFA, but has nondeterministic computation

Nondeterminism:

• Can have multiple (simultaneous) execution paths


• Strings are accepted if there exists at least one execution path that accepts
(still need to read all symbols of string)
0, 1 1

0 𝜀

0
Nondeterministic Finite Automata (NFA)
0, 1 1

0 𝜀

0
Differences between NFA and DFA state diagrams:
1. Transitions go from states to sets of states
• From a state 𝒒, reading symbol 𝒂 can transition to more than one state

• We can also not have transitions for a symbol 𝒂 out of a state 𝒒

• Formally 𝜹: 𝑄 × Σ ∪ 𝜀 → 𝓟(𝑄)
𝜺
2. We allow empty transitions (𝜺-transitions)
• Can take this transition without reading any symbol

• Essentially a free transition from a state to another state


NFA Example 1
0, 𝜀
0, 1
𝑴𝟏 1 𝑞2 𝑞3
0, 1
𝑞1
1
𝑞4
𝜀
0, 1

𝑴𝟏 = 𝒒𝟏 , 𝒒𝟐 , 𝒒𝟑 , 𝒒𝟒 , 𝟎, 𝟏 , 𝜹, 𝒒𝟏 , {𝒒𝟒 } with 𝜹: 𝑸 × 𝚺 ∪ 𝜺 → 𝓟 𝑸 defined by

𝜹 𝟎 𝟏 𝜺
𝑞1 {𝑞1 } {𝑞1 , 𝑞2 } {𝑞4 }
𝑞2 {𝑞3 , 𝑞4 } {𝑞4 } {𝑞3 }
𝑞3 ∅ {𝑞4 } ∅ State diagram omits
𝑞4 {𝑞4 } {𝑞4 } ∅ transitions into ∅
NFA Example 1
0, 𝜀
0, 1
𝑴𝟏 1 𝑞2 𝑞3
0, 1
𝑞1
1
𝑞4
𝜀
0, 1

Is the string 𝒘 = 𝟏 accepted by 𝑴𝟏 ? Yes

Is the string 𝒘 = 𝟏𝟎𝟏 accepted by 𝑴𝟏 ? Yes


NFA Example 1
0, 𝜀
0, 1
𝑴𝟏 1 𝑞2 𝑞3
0, 1
𝑞1
1
𝑞4
𝜀
0, 1

What is the 𝑳 𝑴𝟏 ?
• Every string in 𝚺 ∗ is accepted

• 𝑳 𝑴𝟏 = 𝚺 ∗
NFA Example 2
0, 𝜀
0, 1
𝑴𝟐 1 𝑞2 𝑞3
0
𝑞1
𝜀
𝑞4
𝜀
0, 1

𝑴𝟐 = 𝒒𝟏 , 𝒒𝟐 , 𝒒𝟑 , 𝒒𝟒 , 𝟎, 𝟏 , 𝜹, 𝒒𝟏 , {𝒒𝟏 , 𝒒𝟒 } with 𝜹: 𝑸 × 𝚺 ∪ 𝜺 → 𝓟 𝑸 defined by

𝜹 𝟎 𝟏 𝜺
𝑞1 {𝑞1 } {𝑞1 , 𝑞2 } {𝑞4 }
𝑞2 {𝑞3 , 𝑞4 } ∅ {𝑞3 }
𝑞3 ∅ ∅ {𝑞4 }
𝑞4 {𝑞4 } {𝑞4 } ∅
NFA Example 2
0, 𝜀
0, 1
𝑴𝟐 1 𝑞2 𝑞3
0
𝑞1
𝜀
𝑞4
𝜀
0, 1

Does 𝑳 𝑴𝟐 = 𝑳 𝑴𝟏 ?
• Every string in 𝚺 ∗ is also accepted by 𝑴𝟐

• 𝑳 𝑴𝟐 = 𝑳 𝑴𝟏
NFA Example 3
0, 𝜀
0
𝑴𝟑 1 𝑞2 𝑞3
0
𝑞1
𝜀
𝑞4
𝜀
0

𝑴𝟑 = 𝒒𝟏 , 𝒒𝟐 , 𝒒𝟑 , 𝒒𝟒 , 𝟎, 𝟏 , 𝜹, 𝒒𝟏 , {𝒒𝟏 , 𝒒𝟒 } with 𝜹: 𝑸 × 𝚺 ∪ 𝜺 → 𝓟 𝑸 defined by

𝜹 𝟎 𝟏 𝜺
𝑞1 {𝑞1 } {𝑞2 } {𝑞4 }
𝑞2 {𝑞3 , 𝑞4 } ∅ {𝑞3 }
𝑞3 ∅ ∅ {𝑞4 }
𝑞4 {𝑞4 } ∅ ∅
NFA Example 3
0, 𝜀
0
𝑴𝟑 1 𝑞2 𝑞3
0
𝑞1
𝜀
𝑞4
𝜀
0

Does 𝑳 𝑴𝟑 = 𝑳 𝑴𝟏 ?
• No, not every string in 𝚺 ∗ is accepted by 𝑴𝟑

• E.g. 𝒘 = 𝟏𝟏 is not accepted by 𝑴𝟑


Formal Definition: Nondeterministic Finite Automaton

A nondeterministic finite automaton (NFA) is a 5-tuple (𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) where


• 𝑸 is a finite set called the states

• 𝚺 is a finite set called the alphabet

• 𝜹: 𝑸 × 𝚺 ∪ {𝜺} → 𝓟 𝑸 is the transition function

• 𝒒𝟎 ∈ 𝑸 is the start state

• 𝑭 ⊆ 𝑸 is the set of accept states


NFA: Formal Definition of Computation

Let 𝑴 = (𝑸, 𝚺, 𝜹, 𝒒𝟎 , 𝑭) be an NFA and let 𝒘 = 𝒘𝟏 𝒘𝟐 … 𝒘𝒏 be a string over 𝚺

Then 𝑴 accepts 𝒘 if
• we can write 𝒘 = 𝒚𝟏 𝒚𝟐 … 𝒚𝒎 with 𝒚𝒊 ∈ 𝚺 ∪ {𝜺}
• and there is a sequence of states 𝒓𝟎 , 𝒓𝟏 , 𝒓𝟐 , … , 𝒓𝒎 in 𝑸 such that
1. 𝒓𝟎 = 𝒒𝟎

2. 𝜹 𝒓𝒊 , 𝒚𝒊+𝟏 = 𝒓𝒊+𝟏

3. 𝒓𝒎 ∈ 𝑭

𝑴 recognizes language 𝑳 if 𝑳 = 𝑳 𝑴 = 𝒘 ∈ 𝚺 ∗ | 𝑴 accepts 𝒘


NFA Computation Example
Is the string 𝒘 = 𝟏𝟏𝟎𝟏 in 𝑳 𝑴 ?
0, 𝜀 𝑴
0, 1
1 𝑞2 𝑞3
0, 1
𝟏𝟏𝟎𝟏 𝑞1
1
𝑞4
𝜀
0, 1

• We can rewrite 𝟏𝟏𝟎𝟏 as 𝒘 = 𝟏𝜺𝟏𝟎𝟏 which gives state sequence 𝑞1 , 𝑞1 , 𝑞4 , 𝑞4 , 𝑞4 , 𝑞4


• (There are also other execution paths from start state to accept state)
• Note that the state sequence 𝑞1 , 𝑞1 , 𝑞1 , 𝑞1 , 𝑞1 does not yield acceptance, but 𝒘 ∈ 𝑳 𝑴

• Since there is at least one accepting execution path, 𝒘 ∈ 𝑳 𝑴

You might also like