You are on page 1of 25

CENG205 - Theory of Computation

Assist. Prof. Dr. Emre ŞATIR


Week 4
Nondeterminism
For each state in the machine (which comes out of this state) there is an
arrow corresponding to each symbol in the alphabet.
Every deterministic finite automaton is automatically a nondeterministic finite automaton.
Nondeterministic Finite Automata

Every state of a DFA always has exactly one exiting transition arrow for each symbol in the alphabet.
In an NFA, a state may have zero, one, or many exiting arrows for each alphabet symbol.

In a DFA, labels on the transition arrows are symbols from the alphabet.
An NFA may have arrows labeled with members of the alphabet or ε. Zero, one, or many arrows
may exit from each state with the label ε.
ε-transition is a “free” move without reading input.
Nondeterministic Finite Automata
a
𝑁1 a
b a,ε
𝑞1 𝑞2 𝑞3 𝑞4
b

Accept input if some path leads to accept. (Acceptance always overrules rejection! Acceptance dominates!)

Dead configuration: If the next input symbol doesn’t appear on any of the arrows exiting the state occupied by
a copy of the machine, that copy of the machine dies, along with the branch of the computation associated
with it.
Example inputs
ab accept
aa reject
aba accept
abb reject
aab accept
Ways to Think About Nondeterminism

Computational: Fork new parallel thread and accept if any thread leads to an accept
state.

Mathematical: Tree with branches. Accept if any branch leads to an accept state.

Magical: Guess at each nondeterministic step which way to go. Machine always makes
the right guess that leads to accepting, if possible.
NFA – Formal Definition
a
𝑁1 a
b a,ε
𝑞1 𝑞2 𝑞3 𝑞4
b

Defn: A nondeterministic finite automaton (NFA)


𝑁 is a 5-tuple (𝑄, Σ, 𝛿, 𝑞0, 𝐹)

- all same as before except 𝛿


- 𝛿: 𝑄 × Σε → 𝓟 𝑄 = 𝑅 𝑅 ⊆ 𝑄}
power set
Σ ∪ {ε}
- In the 𝑁1 example: 𝛿 𝑞1 , a = {𝑞1 , 𝑞2 }
𝛿 𝑞1 , b = ∅
NFA – Formal Definition
NFA – Examples
Design a DFA that accepts all strings ending with ‘1’.

Design a NFA that accepts all strings ending with ‘1’.


NFA – Examples
Design a DFA that accepts all strings starting with ‘1’.

Design a NFA that accepts all strings starting with ‘1’.


NFA – Examples
Design a NFA that accepts all strings starting with “10”.

Design a NFA that accepts all strings that contains ‘0’.

* Note that deleting any of the 0's in states A or B will not change the result!
NFA – Examples
Design a NFA that accepts all strings that contains “01”.

Design a NFA that accepts all strings that ends with “11”.
NFA – Examples
The following NFA has an input alphabet {0} consisting of a single symbol. An alphabet containing only one
symbol is called a unary alphabet.

This machine accepts all strings of the form 0k where k is a multiple of 2 or 3. For example, it accepts the strings ε,
00, 000, 0000, and 000000, but not 0 or 00000.
NFA – Examples

This machine accepts the language consisting of all strings over {0,1} containing a 1 in the third position from
the end (e.g., 000100 is in A but 0011 is not).

The smallest DFA for this language contains eight states.

Understanding the functioning of the NFA is much easier, as you may see by examining the above figure for the DFA.
Nondeterminism doesn’t correspond
to a physical machine we can build.
However, it is useful mathematically.

Every NFA can be converted into an equivalent DFA, and constructing NFAs is sometimes easier than directly constructing DFAs.

An NFA may be much smaller than its deterministic counterpart, or its functioning may be easier to understand.
EQUIVALENCE OF NFAs AND DFAs

That means every NFA can be converted an equivalent DFA


EQUIVALENCE OF NFAs AND DFAs
We say that two machines are equivalent if they recognize the same language.

Deterministic and nondeterministic finite automata recognize the same class of languages (Regular Languages).

Such equivalence is both surprising and useful.

It is surprising because NFAs appear to have more power than DFAs, so we might expect that NFAs
recognize more languages.

It is useful because describing an NFA for a given language sometimes is much easier than describing a
DFA for that language.
EQUIVALENCE OF NFAs AND DFAs
We state that every NFA can be converted into an equivalent DFA.

Thus, nondeterministic finite automata give an alternative way of characterizing the regular languages.

So,
A language is regular if some nondeterministic finite automaton recognizes it.
Converting NFAs to DFAs – Subset Construction Method

* C is dead/trap state
Converting NFAs to DFAs – Subset Construction Method
Converting NFAs to DFAs – Subset Construction Method
Return to Closure Properties
Recall Theorem: If 𝐴1 , 𝐴2 are regular languages, so is 𝐴1 ∪ 𝐴2
(The class of regular languages is closed under union)
New Proof (sketch): Given DFAs 𝑀1 and 𝑀2 recognizing 𝐴1 and 𝐴2
Construct NFA 𝑀 recognizing 𝐴1 ∪ 𝐴2

𝑀 𝑀1
Nondeterminism
parallelism
ε vs
guessing
𝑀2
ε
Closure under ∘ (concatenation)
Theorem: If 𝐴1 , 𝐴2 are regular languages, so is 𝐴1 𝐴2
Proof sketch: Given DFAs 𝑀1 and 𝑀1 recognizing 𝐴1 and 𝐴2
Construct NFA 𝑀 recognizing 𝐴1 𝐴2

𝑀1 𝑀2
ε
𝑀 should accept input 𝑤
ε if 𝑤 = 𝑥𝑦 where
𝑀1 accepts 𝑥 and 𝑀2 accepts 𝑦.

𝑤=
𝑥 𝑦

Nondeterministic 𝑀′ has the option


to jump to 𝑀2 when 𝑀1 accepts.
Closure under ∗ (star)
Theorem: If 𝐴 is a regular language, so is 𝐴∗
Proof sketch: Given DFA 𝑀 recognizing 𝐴
Construct NFA 𝑀′ recognizing 𝐴∗

𝑀′
𝑀 ε 𝑀′ should accept input 𝑤
ε if 𝑤 = 𝑥1 𝑥2 … 𝑥𝑘
ε
where 𝑘 ≥ 0 and 𝑀 accepts each 𝑥𝑖

𝑤=
𝑥1 𝑥2 𝑥3 𝑥4
Make sure 𝑀′ accepts ε

You might also like