Sunteți pe pagina 1din 50

CS-850: Advanced

Theory of Computation
(Spring 2020)

Lecture 4
Adnan Rashid

Adnan Rashid Advanced Theory of Computation 1


DFA Summary

Given the current state, we know that


what is the next state
• Only one unique next state
• No choices

Adnan Rashid Advanced Theory of Computation 2


Non-deterministic Finite
Automaton (NFA)
Given the current state, there may be
multiple next states
• The next state is chosen at random
• All next states are chosen
• In parallel
• Pursued simultaneously

Adnan Rashid Advanced Theory of Computation 3


Non-deterministic Finite
Automaton (NFA)

Alphabet = {a}

Two choices
No transition

No transition

Adnan Rashid Advanced Theory of Computation 4


NFA: First Choice

Adnan Rashid Advanced Theory of Computation 5


NFA: First Choice

Adnan Rashid Advanced Theory of Computation 6


NFA: First Choice

All input is consumed


“accept”

Adnan Rashid Advanced Theory of Computation 7


NFA: Second Choice

Adnan Rashid Advanced Theory of Computation 8


NFA: Second Choice

Input cannot be consumed

Automaton Halts

“reject”

Adnan Rashid Advanced Theory of Computation 9


NFA Accepting a String

An NFA accepts a string

▪ If there is a computation of the NFA that


accepts the string

• All the input string is processed and the


automaton is in an accepting state

Adnan Rashid Advanced Theory of Computation 10


Example

aa is accepted by the NFA


“accept”
q1 a q2
a
q0
a
q3 “reject”
This computation This computation
accepts aa is ignored
Adnan Rashid Advanced Theory of Computation 11
Rejection Example 1

Adnan Rashid Advanced Theory of Computation 12


First Choice

“reject”

Adnan Rashid Advanced Theory of Computation 13


Second Choice

Adnan Rashid Advanced Theory of Computation 14


Second Choice

“reject”

Adnan Rashid Advanced Theory of Computation 15


Rejection Example 2

Adnan Rashid Advanced Theory of Computation 16


First Choice

Adnan Rashid Advanced Theory of Computation 17


First Choice

Input cannot be consumed


“reject”

Automaton halts

Adnan Rashid Advanced Theory of Computation 18


Second Choice

Adnan Rashid Advanced Theory of Computation 19


Second Choice

Input cannot be consumed

Automaton halts

“reject”

Adnan Rashid Advanced Theory of Computation 20


NFA Rejecting a String
An NFA rejects a string

▪ If there is no computation of the NFA


that accepts the string
▪ For each computation
• All the input is consumed and the
automaton is in an non-accepting state
▪ OR
• The input cannot be consumed
Adnan Rashid Advanced Theory of Computation 21
Example 1
a is rejected by the NFA
“reject”

“reject”

All possible computations lead to rejection


Adnan Rashid Advanced Theory of Computation 22
Example 2
aaa is rejected by the NFA

“reject”

“reject”

All possible computations lead to rejection


Adnan Rashid Advanced Theory of Computation 23
Language Accepted

Language accepted: L = {aa}

Adnan Rashid Advanced Theory of Computation 24


Lambda Transitions

Adnan Rashid Advanced Theory of Computation 25


Lambda Transitions

Adnan Rashid Advanced Theory of Computation 26


Lambda Transitions

Adnan Rashid Advanced Theory of Computation 27


Lambda Transitions
input tape head does not move

Automaton changes state

Adnan Rashid Advanced Theory of Computation 28


Lambda Transitions
all input is consumed

“accept”

String aa is accepted
Adnan Rashid Advanced Theory of Computation 29
Rejection Example

Adnan Rashid Advanced Theory of Computation 30


Rejection Example

Adnan Rashid Advanced Theory of Computation 31


Rejection Example
(read head doesn’t move)

Adnan Rashid Advanced Theory of Computation 32


Rejection Example
Input cannot be consumed

Automaton halts
“reject”

String aaa is rejected


Adnan Rashid Advanced Theory of Computation 33
Accepted Language

Language accepted: L = {aa}

Adnan Rashid Advanced Theory of Computation 34


NFA Example 2

Adnan Rashid Advanced Theory of Computation 35


NFA Example 2

Adnan Rashid Advanced Theory of Computation 36


NFA Example 2

Adnan Rashid Advanced Theory of Computation 37


NFA Example 2

“accept”

Adnan Rashid Advanced Theory of Computation 38


NFA Example 2

Adnan Rashid Advanced Theory of Computation 39


NFA Example 2

Adnan Rashid Advanced Theory of Computation 40


NFA Example 2

Adnan Rashid Advanced Theory of Computation 41


NFA Example 2

Adnan Rashid Advanced Theory of Computation 42


NFA Example 2

Adnan Rashid Advanced Theory of Computation 43


NFA Example 2

Adnan Rashid Advanced Theory of Computation 44


NFA Example 2

“accept”

Adnan Rashid Advanced Theory of Computation 45


Activity
Write the Language accepted by the following
automaton
L = ab, abab, ababab, ...
+
= ab

Adnan Rashid Advanced Theory of Computation 46


NFA Example 3
Language accepted

L( M ) =  , 10, 1010, 101010, ...


= 10*

(redundant
state)

Adnan Rashid Advanced Theory of Computation 47


Remarks

▪ The  symbol never appears on the input tape


Simple automata

L(M1 ) = {} L(M 2 ) = {λ}

Adnan Rashid Advanced Theory of Computation 48


NFA vs DFA
▪ NFAs are interesting because we can express
languages easier than DFAs

Adnan Rashid Advanced Theory of Computation 49


Thank you!

Adnan Rashid Advanced Theory of Computation 50

S-ar putea să vă placă și