0% found this document useful (0 votes)
32 views27 pages

Theory of Computation CSE 4040: Nondeterministic Finite Automata (NFA)

The document discusses nondeterministic finite automata (NFA). It defines an NFA as a quintuple (Q, Σ, δ, q0, F) where δ maps to sets of states rather than single states. This allows for multiple transitions from a state based on an input symbol. An NFA accepts a string if any sequence of transitions leads to a final state. The document provides examples of NFAs and their extended transition functions. It defines the language accepted by an NFA and discusses how NFAs and DFAs accept the same regular languages.

Uploaded by

testingblah6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views27 pages

Theory of Computation CSE 4040: Nondeterministic Finite Automata (NFA)

The document discusses nondeterministic finite automata (NFA). It defines an NFA as a quintuple (Q, Σ, δ, q0, F) where δ maps to sets of states rather than single states. This allows for multiple transitions from a state based on an input symbol. An NFA accepts a string if any sequence of transitions leads to a final state. The document provides examples of NFAs and their extended transition functions. It defines the language accepted by an NFA and discusses how NFAs and DFAs accept the same regular languages.

Uploaded by

testingblah6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Theory of Computation

CSE 4040
Nondeterministic Finite Automata(NFA)

21-12-2023 1
Recall, Deterministic Finite Automata

The processing begins in𝑀’s start state.


 The automaton receives the symbols from the input string one by one from left to
right.
After reading each symbol,𝑀 moves from one state to another along the transition that
has that symbol as its label.
When it reads the last symbol, 𝑀 produces its output.
 The output is accept if 𝑀 is now in a final state.
21-12-2023
 It is reject if it is not. 2
Recall, Deterministic Finite Automata
a a a a

a a
q0 q1 a a
𝒒𝟐
q0 q1 𝒒𝟐

𝛿 𝒒𝟎 , 𝝀 = 𝒒𝟎 𝛿 𝒒𝟏 , 𝑎 = 𝒒𝟐

a a a a

a a
q0
a
q1
a
𝒒𝟐
q0 q1 𝒒𝟐

𝛿 𝒒𝟐 , 𝝀 = 𝒒𝟐

21-12-2023𝛿 𝒒𝟎 , 𝑎 = 𝒒 𝟏 3
Recall, Deterministic Finite Automata
𝛿 ∗ 𝒒𝟎 , 𝑎𝑎 = 𝛿(𝛿 ∗ 𝒒𝟎 , 𝑎 , 𝑎)
= 𝛿(𝛿 ∗ 𝒒𝟏 , 𝑎 , 𝝀)
a a
= 𝛿 𝒒𝟐 , 𝝀 q0 q1 𝒒𝟐
= 𝒒𝟐
𝑎𝑎 ∈ 𝐿(𝑀)

21-12-2023 4
Nondeterministic Finite Accepters(NFA)
Σ = {𝑎}
there are two transitions labelled a out of 𝑞0
and 𝑞3 is lacking any transition for input.
No Transition

𝛿 𝑞0 , 𝑎 = 𝑞1 , 𝛿 𝑞0 , 𝑎 = 𝑞4 , 𝛿 𝑞3 , 𝑎 = nowhere (as transition to the empty set)


𝛿 𝑞3 , 𝑎 =𝜙 (transition undefined)

21-12-2023 dead configuration 5


2.2 Nondeterministic Finite Accepters (𝜆 Transition)

a a a a

q0 a q1  q2 a q3 q0 a q1  q2 a q3

a a
a a

q0 a q1  q2 a q3 q0 a q1  q2 a q3

21-12-2023
The 𝜆 symbol is never seen on the input tape. 6
2.2 Nondeterministic Finite Accepters (𝜆 − NFA)
Example Σ = {0,1}

 Accepting Strings 𝜆,10,1010,101010

 Reject : 0,1,11

 for 10 there are two alternative walks , one leading to


𝛿 𝑞0 , 𝜆 = 𝑞0 , 𝛿 𝑞0 , 𝜆 = 𝑞2 , 𝛿 𝑞0 , 1 = 𝑞1 , 𝑞0 , the other to 𝑞2 .
 Even though 𝑞2 is not a final state, the string is accepted
𝛿 𝑞1 , 0 = 𝑞0 , 𝛿 𝑞1 , 0 = 𝑞2 , 𝛿 𝑞1 , 1 = 𝑞2 because one walk leads to a final state.

𝛿 𝑞2 , 0 = 𝜙 , 𝛿 𝑞2 , 1 = 𝜙

Myanmar Institute of Information Technology 7


2.2 Nondeterministic Finite Accepters

multiple edges leaving one vertex labelled with the same symbol

no edge leaving vertex labelled with symbol

edges leaving vertex labelled with 𝜆


 can take 𝜆 − edge without reading any input symbol

Myanmar Institute of Information Technology 8


2.2 Nondeterministic Finite Accepters
The three difference between dfas and nfas are
1. dfa : a single state of Q can be reached by the transition
nfa : the set of all possible states of Q can be reached by the transition
2. dfa : consumes input with each movement
nfa : can move without consuming an input symbol(𝜆)
3. dfa : moves for every input and state
nfa : there is no transition defined for some situation.

An nfa accepts a string if some possible sequence of moves ends in a final state.
An nfa rejects a string if no possible sequence of moves ends a final state.

Myanmar Institute of Information Technology 9


Nondeterministic Finite Accepters(NFA)
Definition of a Nondeterministic Accepters
A nondeterministic finite acceptor or nfa is defined by the quintuple
M=(Q,Σ, 𝛿, 𝑞0 , 𝐹) , where Q, Σ, 𝑞0 , F are defined as for deterministic finite
accepters ,but
𝛿: 𝑄 × Σ ∪ 𝜆 ⟶ 2𝑄 .

21-12-2023 10

Extended transition function 𝜹

If 𝛿 ∗ 𝑞𝑖 , 𝑤 = 𝑄𝑗 then 𝑄𝑗 is the set of all possible states the


automaton may be in, having started in state 𝑞𝑖 and having read w.

21-12-2023 11
Extended transition function 𝜹 ∗
𝛿 ∗ 𝑞0 , 𝑎 = {𝑞1 }
𝛿 ∗ 𝑞0 , 𝑎𝑏 = {𝑞2 , 𝑞3 , 𝑞0 }

q4 q5
a a q4 q5
q0 a q1 b q2  q3 a a
q0 a q1 b q2  q3

𝛿 ∗ 𝑞0 , 𝑎𝑎 = {𝑞4 , 𝑞5 }

q4 q5
a a
q0 a q1 b q2  q3

21-12-2023  12
Extended transition function 𝜹∗
 Use 𝛿 ∗ to describe how the string 01010 is processed by the NFA.
𝛿 ∗ 𝑞0 , 𝟎1010 = δ 𝛿 ∗ 𝑞0 , 0101 , 0

1 0,1 = δ 𝛿 ∗ 𝑞0 , 0101 , 0
q0 q1 𝒒𝟐
= δ 𝛿 ∗ 𝑞0 , 101 , 0

= δ 𝛿 ∗ {𝑞0 , 𝑞1 }, 01 , 0
M
= δ 𝛿 ∗ ( 𝑞0 , 0) ∪ (𝑞1 , 0), 1 , 0

M=({𝑞0 , 𝑞1 , 𝑞2 },{0,1}, 𝑞0 , δ, {𝑞2 }) = δ(𝛿 ∗ ({𝑞0 } ∪ {𝑞2 }, 1), 0)


where the transition function δ is
= δ(𝛿 ∗ ({𝑞0 , 𝑞2 }, 1), 0)
δ 0 1
= δ 𝛿 ∗ (𝑞0 , 1) ∪ (𝑞2 , 1), 0
𝑞0 {𝑞0 } {𝑞0 , 𝑞1 }
𝑞1 {𝑞2 } {𝑞2 } = δ ({𝑞0 , 𝑞1 } ∪ ∅), 0) = δ( 𝑞0 , 𝑞1 , 0)

𝑞2 ∅ ∅ = δ( 𝑞0 , 0 ∪ 𝑞1 , 0 , 𝜆) = δ({𝑞0 } ∪ {𝑞2 }, 𝜆)
= δ( 𝑞0 , 𝜆 ∪ 𝑞2 , 𝜆 )
L(M)= all the strings ending in 10 (or) 11. = {𝑞0 } ∪ {𝑞2 }
= {𝑞0 , 𝑞2 }
21-12-2023 13
Nondeterministic Automata NFA
Definition 2.6
The language L accepted by nfa 𝑀 = (𝑄, Σ, 𝛿, 𝑞0 , 𝐹) is defined as the set of all
strings accepted in the above sense. Formally,
𝐿 𝑀 = {𝑤 ∈ Σ ∗ : 𝛿 ∗ (𝑞0 , 𝑤) ∩ 𝐹 ≠ 𝜙}.
In words, the language consists of all strings w for which there is a walk labelled
w from the initial vertex of the transition graph to some final vertex.

NFAs accept the Regular Languages.

21-12-2023 14
Example
Σ = {𝑎, 𝑏}
(1) 𝐿1 = {𝑠𝑡𝑎𝑟𝑡𝑠 𝑤𝑖𝑡ℎ ′𝑎′}

(2) 𝐿2 = {𝑐𝑜𝑛𝑡𝑎𝑖𝑛 ′𝑎′}

(3) 𝐿3 = {𝑒𝑛𝑑𝑠 𝑤𝑖𝑡ℎ ′𝑎′}

(4) 𝐿4 = {𝑠𝑡𝑎𝑟𝑡𝑠 𝑤𝑖𝑡ℎ ′𝑎𝑏′}

(4) 𝐿5 = {𝑐𝑜𝑛𝑡𝑎𝑖𝑛 ′𝑎𝑏′}

(5) 𝐿6 = {𝑒𝑛𝑑𝑠 𝑤𝑖𝑡ℎ ′𝑎𝑏′}

21-12-2023 15
Example (1): What is the language accepted by the automaton in fig?

L={(10)𝑛 : 𝑛 ≥ 0}

what happens w=110 ?

𝛿 ∗ 𝑞0 , 110 = ∅ 𝛿 𝑞2 , 0 = 𝜙 (transition undefined)

21-12-2023 16
2)Design an nfa with no more than five states for the set 𝑎𝑏𝑎𝑏 𝑛 : 𝑛 ≥ 0 ∪
{𝑎𝑏𝑎𝑛 : 𝑛 ≥ 0}.

21-12-2023 17
Equivalence of Deterministic and Nondeterministic Finite Automata

21-12-2023 18
Equivalence of DFA’s and NFA’s
 Every DFA is also an NFA by definition.

 There is no simply non-determinism.

 Every NFA can be converted into an equivalent DFA.

 Two equivalent machines recognize the same language.

 Non-intuitive, as we’d expect NFA’s to be more powerful.

 Useful, as describing an NFA is much simpler.

Proof is the subset construction.

The number of states of the DFA can be exponential in the number of states of the NFA.

21-12-2023 19
Equivalence of Machines
• Definition 2.7
Two finite accepters 𝑀1 and 𝑀1 are said to be equivalent if
L(𝑀1 ) = L(𝑀2 ).
That is, if they both accept the same language.

21-12-2023 20
Equivalence of DFAs and NFAs

L(𝑀1 )={(10)𝑛 , 𝑛 ≥ 0}

𝑀1 (NFA)

L(𝑀2 )={(10)𝑛 , 𝑛 ≥ 0}

𝑀2 (DFA)
21-12-2023
Thus, 𝑀1 is equivalent to 𝑀2 . 21
Subset Construction

Given an NFA(𝑄, Σ, 𝛿𝑁 , 𝑞0 , 𝐹) , construct equivalent DFA with:


 States P(Q) (set of subsets of Q).
 Inputs Σ.
 Start state {𝑞0 } .
 Final states = all those with a member of F.

Note:

 The DFA states have names that are sets of NFA states.

 But as a DFA state, an expression like {𝑝, 𝑞} must read as a single symbol.

21-12-2023 22
Subset construction
• Example: We ‘ll construct the DFA for the following NFA which recognizes strings in {0,1}∗
containing a 1 in the second position from the end.

Solution:
Construction DFA 𝑀1 as 𝑀1 = (𝑄1 , 0,1 , 𝜹𝑫 , 𝑨 , 𝑭)
where 𝑄1 = 𝑃 𝑄 = 2𝑄 =
{∅, 𝐴 , 𝐵 , 𝐶 , 𝐴, 𝐵 , 𝐴, 𝐶 , 𝐵, 𝐶 , {𝐴, 𝐵, 𝐶}}

M=({A,B,C},{0,1}, 𝜹𝑵 ,A,F) 𝛿𝐷 𝐴 , 0 = {𝐴}


𝛿𝐷 𝐴 , 1 = {𝐴, 𝐵} (New single state)

𝜹𝑵 0 1 𝛿𝐷 𝐴, 𝐵 , 0 = 𝛿𝑁 𝐴 , 0 ∪ 𝛿𝑁 𝐵, 0 = 𝐴 ∪ 𝐶 = {𝐴, 𝐶} (New single state)


𝛿𝐷 𝐴, 𝐵 , 1 = 𝛿𝑁 𝐴 , 1 ∪ 𝛿𝑁 𝐵, 1 = 𝐴, 𝐵 ∪ 𝐶 = {𝐴, 𝐵, 𝐶} (New single state)
A {A} {A,B} 𝛿𝐷 𝐴, 𝐶 , 0 = 𝛿𝑁 𝐴 , 0 ∪ 𝛿𝑁 𝐶, 0 = 𝐴 ∪ Φ = {𝐴}
𝛿𝐷 𝐴, 𝐶 , 1 = 𝛿𝑁 𝐴 , 1 ∪ 𝛿𝑁 𝐶, 1 = 𝐴, 𝐵 ∪ Φ = {𝐴, 𝐵}
B {C} {C}
𝛿𝐷 𝐴, 𝐵, 𝐶 , 0 = 𝛿𝑁 𝐴 , 0 ∪ 𝛿𝑁 𝐵 , 0 ∪ 𝛿𝑁 𝐶 , 0 = 𝐴 ∪ {𝐶} ∪ Φ = {𝐴, 𝐶}
*C 𝜙 𝜙 𝛿𝐷 𝐴, 𝐵, 𝐶 , 1 = 𝛿𝑁 𝐴 , 1 ∪ 𝛿𝑁 𝐵 , 1 ∪ 𝛿𝑁 𝐶 , 1 = 𝐴, 𝐵 ∪ {𝐶} ∪ Φ = {𝐴, 𝐵, 𝐶}

21-12-2023 𝛿𝑁∗ 𝐴, 10011 = 𝐶 ∈ 𝐹 23


Subset construction 𝜹𝑫 0 1
𝛿𝐷 𝐴 , 0 = {𝐴}
𝛿𝐷 𝐴 , 1 = {𝐴, 𝐵} {A} {A} {A,B}

𝛿𝐷 𝐴, 𝐵 , 0 = 𝛿𝑁 𝐴 , 0 ∪ 𝛿𝑁 𝐵, 0 = 𝐴 ∪ 𝐶 = {𝐴, 𝐶} {A,B} {A,C} {A,B,C}


𝛿𝐷 𝐴, 𝐵 , 1 = 𝛿𝑁 𝐴 , 1 ∪ 𝛿𝑁 𝐵, 1 = 𝐴, 𝐵 ∪ 𝐶 = {𝐴, 𝐵, 𝐶}
*{A,C} {𝐴} {𝐴, 𝐵}
𝛿𝐷 𝐴, 𝐶 , 0 = 𝛿𝑁 𝐴 , 0 ∪ 𝛿𝑁 𝐶, 0 = 𝐴 ∪ Φ = {𝐴} *{A,B,C} {A,C} {A,B,C}
𝛿𝐷 𝐴, 𝐶 , 1 = 𝛿𝑁 𝐴 , 1 ∪ 𝛿𝑁 𝐶, 1 = 𝐴, 𝐵 ∪ Φ = {𝐴, 𝐵}

𝛿𝐷 𝐴, 𝐵, 𝐶 , 0 = 𝛿𝑁 𝐴 , 0 ∪ 𝛿𝑁 𝐵 , 0 ∪ 𝛿𝑁 𝐶 , 0 = 𝐴 ∪ {𝐶} ∪ Φ = {𝐴, 𝐶}
𝛿𝐷 𝐴, 𝐵, 𝐶 , 1 = 𝛿𝑁 𝐴 , 1 ∪ 𝛿𝑁 𝐵 , 1 ∪ 𝛿𝑁 𝐶 , 1 = 𝐴, 𝐵 ∪ {𝐶} ∪ Φ = {𝐴, 𝐵, 𝐶}

𝛿𝐷∗ {𝐴}, 10011 = {𝐴, 𝐵, 𝐶} ∈ 𝐹

NFA
21-12-2023 24
DFA
Equivalence of DFAs and NFAs
Every DFA is obviously an NFA.
 A language accepted by a DFA is also accepted by an NFA.

Any NFA can be converted to an equivalent DFA.

 A language accepted by a NFA is also accepted by an DFA.

Thus, DFAs and NFAs are equally powerful.

21-12-2023 25
Epsilon-Closures
 It is a set of reachable states from a given state with 𝜀 − 𝑡𝑟𝑎𝑛𝑠𝑖𝑡𝑖𝑜𝑛.
0 1 0 1

q0 𝜀 𝒒𝟏 𝜀 𝒒𝟐 q0 𝜀 𝒒𝟏 𝜀 𝑞2

0
1
 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞0 = {𝑞0 , 𝑞1 , 𝑞2 }
 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞1 = {𝑞1 , 𝑞2 } 𝒒𝟑
 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞2 = {𝑞2 }

 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞0 = {𝑞0 , 𝑞1 , 𝑞2 }
 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞1 = {𝑞1 , 𝑞2 }
 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞2 = {𝑞2 }
 𝜀 − 𝑐𝑙𝑜𝑠𝑢𝑟𝑒 𝑞3 = {𝑞3 }
21-12-2023 26
Summary
DFA’s , NFA’s and 𝜆 − 𝑁𝐹𝐴′ 𝑠 all accept exactly the same set of languages:
the regular languages.

NFA types are easier to design and may have exponentially fewer states than a
DFA.

21-12-2023 27

You might also like