Presentation is loading. Please wait.

Presentation is loading. Please wait.

Theory of Computing Lecture 22 MAS 714 Hartmut Klauck.

Similar presentations


Presentation on theme: "Theory of Computing Lecture 22 MAS 714 Hartmut Klauck."— Presentation transcript:

1 Theory of Computing Lecture 22 MAS 714 Hartmut Klauck

2 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)

3 Example Language that contains all strings having a 1 in the third position from the end

4 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

5 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)

6 Proof A has s states, simulating DFA M has 2 s -1 states Starting state: {q 0 } Accepting states of M: those that contain an accepting state of A Edges: Consider a state {q 1,…, q k } of M. There is an edge labeled with letter a to the state which is the union of the ± (q i,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

7 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)

8 Languages that are not regular Intuitively, DFA cannot count We will see that languages like {0 n 1 n :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

9 The game Two players, Alice and Bob Alice receives an input x 2 § * Bob receives y 2 § * Alice sends a message to Bob, who decides whether x ± y 2 L – ± : concatenation, we will also just write xy Cost of the game: number of messages used

10 Example L={0 n 1 n : n is natural} How many messages are needed? Alice has an input x If x contains a 1 before a 0, or x=0 n 1 n+k she sends the message `reject’ Otherwise 2 cases: – Alice has 0 k : she sends the message `0,k’ – Alice has 0 n 1 k : 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)

11 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

12 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

13 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

14 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

15 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 xy 2 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

16 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

17 Examples Parity: M has only two distinct rows {0 n 1 n }: – Consider the rows of M labeled 0 k for all k=1,…, 1 – The rows are all different [the row for 0 k has a 1 only in column 1 k ] Conclusion: {0 n 1 n : n natural} is not a regular language

18 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


Download ppt "Theory of Computing Lecture 22 MAS 714 Hartmut Klauck."

Similar presentations


Ads by Google