Post on 22-Dec-2015
Theory of Computing
Lecture 22MAS 714
Hartmut Klauck
Nondeterministic Finite Automata
• Definition:– A nondeterministic finite automaton (NFA) is defined
like a DFA, except that there are possibly several transitions from a pair (state, letter) [but at least one]
– For the graph this means that there are several edges from state q labeled with letter a
– Acceptance if there is a path to an accepting state• Note: variants include: allow ² transitions
(transition without reading) and incomplete edge sets (input gets stuck/leads to no state)
Example
• Language that contains all strings having a 1 in the third position from the end
A note
• There is no good `guess and check’ definition of NFA
• One can prove that NFA cannot do all the nondeterministic guesses at the beginning of the computation and then just proceed deterministically– Reason: can store only O(1) guesses in the internal
state, which is not enough
DFA vs. NFA
• Theorem: The set of languages that can be decided by NFA is equal to the set of regular languages
• Proof:• Take any NFA A. We have to find a DFA that decides
the same language as A• Idea: power-set construction:– use one state for every nonempty subset of states of A– After reading a string x the DFA will be in the state that
the set of reachable states of A (on x)
Proof
• A has s states, simulating DFA M has 2s -1 states• Starting state: {q0}• Accepting states of M: those that contain an accepting state
of A• Edges: Consider a state {q1,…, qk} of M. There is an edge
labeled with letter a to the state which is the union of the ±(qi,a) for i=1…k
• Claim: The computation in M on input x ends in the state s that is the set of states in A that can be reached on x– Proof by induction
• Then: M accepts x iff A accepts x
DFA vs. NFA
• Hence every language L decided by an NFA is regular, and there is a DFA for L that is at most exponentially larger than the smallest NFA
• This is also best possible• Note that the size (number of states) of the
NFA/DFA is a constant (independent of the input length)
Languages that are not regular
• Intuitively, DFA cannot count• We will see that languages like {0n1n :n is a natural
number} are not regular• To show this we simulate DFA by a communication
game
• Game is equivalent to the Myhill-Nerode method• Most common approach: pumping lemma– much less general
The game
• Two players, Alice and Bob• Alice receives an input x2§*• Bob receives y2§*• Alice sends a message to Bob, who decides
whether x±y2 L– ±: concatenation, we will also just write xy
• Cost of the game: number of messages used
Example• L={0n1n: n is natural}• How many messages are needed?• Alice has an input x• If x contains a 1 before a 0, or x=0n1n+k she sends the message
`reject’• Otherwise 2 cases:
– Alice has 0k: she sends the message `0,k’– Alice has 0n1k: she sends the message `1,n-k’
• Bob can decide if xy is in L from the message and y• These are infinitely many different messages!• We can still count the number of messages as a function of the
input length m, number of different messages is O(m)
Example 2
• Parity={w: w has odd number of 1’s}• Alice sends the number of 1’s in her part of
the input modulo 2• 2 messages: 0/1• Bob accepts if the message bit is different
from the number of 1’s in his input modulo2
Example 3
• L={w: third last symbol of w is 1}, alphabet={0,1}
• Alice sends last 3 symbols of her input x (if possible)
• Otherwise:– If x=ab, she sends the message for 0ab– If x=a she sends message for 00a– If x is the empty string she sends 000
• Total: 8 messages
Example 3
• L={w: third last symbol of w is 1}, alphabet={0,1}
• Correctness of the protocol:– Given message abc Bob can append his input y
and check if the third last symbol of abcy is 1– If Alice’s input has length 1 or 2 then ab=00 resp.
a=0• DFA with 8 states exists (see next theorem)– Will show later: no DFA for L has less than 8 states
DFA and the game
• Theorem [DFA vs. game]:– If L is regular, then the optimal number of
messages in the game is equal to the smallest number of states in a DFA.
– If L is not regular, then the smallest number of messages is infinite
Application
• How to show that we need many messages?• Consider the infinite matrix M, rows labeled
with all possible x and columns labeled with all possible y and M[x,y]=1 iff xy2 L
• Call this matrix the communication matrix of L• Lemma: The minimum number of messages in
the game is equal to the number of distinct rows in the matrix
Proof
• Two rows labeled x, x’ are distinct if there is a column y where M[x,y]=1 and M[x’,y]=0– or vice versa
• If Alice sends the same message on x and x’ then Bob cannot distinguish them, so there is an error either on xy or on x’y
• On the other hand it is enough for Alice to send the same message on x, x’ if they their rows are not distinct
Examples
• Parity: M has only two distinct rows
• {0n 1n}:– Consider the rows of M labeled 0k for all k=1,…,1– The rows are all different [the row for 0k has a 1
only in column 1k]• Conclusion: {0n 1n: n natural} is not a regular
language
Example
• {w: third last symbol of w is 1}• Consider the rows labelled by all strings of
length 3 over {0,1}– 8 such rows
• Easy to see that these rows are all distinct• Hence no DFA for the language can have less
than 8 states