You are on page 1of 14

Lecture 13: Nondeterministic Finite Automata

Bakhadyr Khoussainov
Computer Science Department, The University of Auckland, New Zealand bmk@cs.auckland.ac.nz

1

Definitions and Examples

We start with an example. For a fixed natural number n ≥ 1, consider the following language L = {uav | u, v ∈ {a, b}⋆ and the length of v is n}. Thus, L consists of all strings w that have an a in the (n + 1)th position from the right of w. Assume that we are asked to design a DFA recognizing L and draw the transition diagram of the automaton. When trying to design a DFA recognizing this language, one soon realizes that such a DFA exists and that it should have many states. We will prove later on that there exists a DFA with 2n states recognizing this language. Moreover, no DFA with less than 2n states recognizes L. An interesting observation, however, is this. Imagine, we are reading an input string w from {a, b}⋆ to determine whether w is in L. If we do not see the symbol a then we reject w. Let’s assume that we have just seen the first a in w. We can make one of the following two guesses: 1. The symbol a we have just seen is in the (n + 1)th position from the right of w. 2. The symbol a we have just seen is not in the (n + 1)th position from the right of w. Suppose we we select the first guess. We change our state, and then try to verify our guess. Let’s call this state the verification state. To verify the correctness of our guess we just need to read the rest of the string and check if the length of the rest of the string is n. To do this, we set the integer variable length to 0 and increment it by 1 each time we read the next input symbol of w. If the length of the rest of the string is strictly less than n, then the guess is incorrect. Now assume that length = n. If the string does not have any more symbols left then the guess is correct. Otherwise, the guess is incorrect. In this case, we need to go back to the position of w where we made the first guess, and select the second guess. Suppose we select the second guess. Call this state the passive state. This means we continue on with the rest of the string just passing through all the b’s until we encounter the next a. When we see the next a, we repeat the same guessing process by selecting either the verification state or the passive state. Thus, while reading w, whenever we see an a we can either stay in the passive state or we can select the verification state and verify the correctness of our guess. An important note is this. If w ∈ L then w is of the form uav where the length of v is n. Therefore, we can act as follows. We stay in the passive state until we read through the

4.entire string u. where P (S) is the power set of S. When we are in the passive state and read the symbol a. 1. We often write (S. I. F = {5}. 6}. Once we finish reading u. to denote NFA. We abbreviate nondeterministic finite automata by N F A. Then all our guesses when we select the verification state will never verify that our guess was correct. B. 1. T is the transition function T : S × Σ → P (S). An example of an NFA In this figure the initial state is the passive state and the state after the initial state is the verification state. F ) as a labeled graph. Formally. σ) = ∅ for some s ∈ S and σ ∈ Σ. The passive state is nondeterministic in the following sense. 3. One is to stay in the passive state. S = {0. . These are called σ-transitions. Keeping this example in mind we give the following central definition: Definition 1. T. In Figure 1 we represent our analysis above by a finite state machine for the case when n = 3. 5. . Σ). a b 0 a 1 a b 2 ab 3 Fig. 2. We put an edge from state s to state p and label it with σ if p ∈ T (s. 3. I ⊆ S is the set of initial states. where 1. We often say automata for short instead of saying nondeterministic finite automata. F. . 5. σ). Since T : S × Σ → P (S) it may well be the case that T (s. F. We call this visual presentation a transition diagram of the automaton. T. S is the set of states. The final states are doubly circled. I = {0}. I. We can visualize an NFA (S. 2. I. 4. 3. I. The states of the NFA are vertices of the graph. The initial states are the vertices that have in-going arrows without a source. this automaton is defined as follows: 1. 4. Σ is a given alphabet. it is not determined which of the following two transition we should make. T. Σ) as it will be clear from T which Σ is used. F ) instead of (S. F ⊆ S is the set of accepting states. we select the verification state and easily verify the correctness of our guess. The table of the transition function T is presented in the next page. 2. and the other is to move to the verification state. We use letters A. Now suppose that w ∈ L. In Figure 2 we present an NFA with 6 states. A nondeterministic finite automaton is a 5-tuple (S. T. .

. (c) Set s = q and print s. How does the automaton A run on the input string w? We define this below and then explain the definition in more detail. I. σi ) for all i = 1. 2. We call a state s of an NFA a nondeterministic state if the state has more than one σ-transitions for some σ ∈ Σ. one. . . Let A = (S. Transition table T of the automaton in figure below. (d) Increment i. It then reads the first input σ1 . 1} 1 {2} 2 {3} 3 {4} 4 ∅ 5 {5} b {0} {2} {3} {4} {5} {5} Table 1. First. Initialize i = 1 and randomly choose an s ∈ I. two or more σ-transitions. a b a b a 0 1 a b 2 a b 3 a b 4 b 5 Fig. . . While i ≤ n do (a) Set σ = σi . σn is a sequence of states s1 . Σ) be an NFA and w be a string σ1 σ2 . w): 1. Every state in a DFA always has exactly one σ-transition for every σ ∈ Σ. the algorithm prints one of the initial states. Another example of an NFA Every DFA is an NFA but the difference between DFA and NFA is this. . A run of A on string w = σ1 . . 2. s2 . σ). T.a 0 {0. . . . This algorithm outputs the states of the DFA M as it reads through the string w. makes a random . σn . . σn can be thought of as an execution the following randomized algorithm Run(M. n. 3. Print s. . . A run of the automaton A on the string σ1 σ2 . in an NFA there could be states that have none. sn+1 such that s1 ∈ I and si+1 ∈ T (si . sn . Definition 2. As opposed to this. F. (b) Randomly choose a state q from T (s. .

The language accepted by M. These copies all make independent transition by splitting themselves and thus making more copies if that is dictated by the transition function. makes a random transition from q. In this case we say that the run s1 . . This continues as before. . If a copy of the automaton is in a state where there are no transitions. . I. . Now we give several simple examples: 1. . If the state is accepting then the automaton accepts the language {λ}. the automaton accepts the language ∅. denoted by L(M). In this figure we can see that the two rightmost paths die out because at state 3 the automaton can not make any transition. at any given stage of the computation there are several copies of the automaton reading the same symbol in parallel.. . Then its computation on ababaab can be represented by the tree in Figure 3. qk .transition from the initial state to one of the states q in T (q0 . the automaton splits itself into k many copies where the ith copy is at state qi . sn+1 is an accepting run. The copy now splits itself into t many new copies where each of them moves along one of the t transitions. then the copy dies. Consider the NFA with exactly one state with no transitions. prints q. . The other paths produce runs of the automaton on the input. The most important thing to remember is that there could be several runs of the automaton on one input w. the automaton A does not accept w if no run of A is accepting. . and there are t transitions from q labeled with σ1 . is the following language: {w | the automaton M accepts w}. σn is this. Informally. . A language L ⊆ Σ ⋆ is NFA recognizable if there exists an NFA M such that L = L(M). s2 . F. Thus. the acceptance of w by A is an existential condition because the condition refers to the existence of an accepting run of A on w. σ1 ). σn if the automaton has a run s1 . Assume that one of these copies is at state q. s2 . Before the automaton starts reading w. . . A has k initial states q1 . consider the automaton represented in Figure 1. The height of the tree is at most n + 1. i = 1. For example. . Every branching node of the tree represents the fact that A splits itself at that node by reading the next symbol from w. Let M = (S. Thus. sn+1 on w such that the state sn+1 is an accepting state. . T. The root of the tree is the start of the computation. Say. We say that a NFA A accepts a string w = σ1 σ2 . Another way of looking at how A runs on w = σ1 σ2 . Definition 4. k. Each copy of A now reads the first symbol σ1 of w. reads the next symbol σ2 . Otherwise. The acceptance of a given string w by A is equivalent to saying that at least one of the runs of A (among possibly several) on w must be an accepting run. . Now we are ready for the next definition: Definition 3. Σ) be an NFA. . . and so on. Yet another helpful way to think about how A runs on w is to represent this as a tree. . One of these runs is such that the end state of the run is the accepting state. . . . The paths of length n + 1 from the root to the leaves correspond to the runs of the automaton on w. A accepts w if in the transition diagram of A there exists a path from an initial state to a final state such that the path is labeled with the string w. Thus.

Therefore every DFA recognizable language is NFA recognizable. We want to construct a DFA B such that L(A) = L(B). Every DFA is an NFA. Let A = (S. 4. b} such that w has an a at the third position from the right. . Let w = σ1 σ2 . I. 3. We design an algorithm that. Let’s use our method of pretending to be a machine and trying to build a DFA recognizing the language of A. Consider the automaton in Figure 2. σn be an input for the NFA A. . produces a DFA B such that L(A) = L(B).0 a a 0 b 0 a 0 b 0 a 0 a 0 b 0 2 a 1 b 3 2 b a 1 a 3 2 a a 1 b 2 a 3 b 1 Fig. 3. Initially we mark every initial state of A. A tree representation of a computation 2. This activates every marked state s as follows. Σ) be an NFA. This automaton accepts all the strings w of the alphabet {a. We read the first symbol σ1 of w. Consider the automaton in Figure 1. We proceed as follows. This automaton accepts all the strings w of the alphabet {a. b} such that w has a substring aub where u is a string of length 3. The intention here is that our current memory consists of all the states that are now marked. In this section we give a positive answer to this question. F. . T. given an NFA A. a natural question to ask is whether every NFA recognizable language is DFA recognizable. 2 Subset construction Since every DFA recognizable language is NFA recognizable.

. . Consider the sequence Q1 . . Q2 = p∈Q1 T (p. σi ). The initial state q0 of B is I. for all i = 1. We repeat the same process by reading the next symbol σ2 . Therefore we have proved the following theorem. . F ) be an NFA. . . qn+1 of A on w. . ′ ′ . Note that if the NFA A has n states then the DFA produced by the subset construction has 2n states. The collection of all the initially marked states has been changed. σ1 ). For any NFA A there exists a DFA B such that A and B are equivalent. σn ). then σ3 . b}⋆ and the length of v is n} discussed at the beginning of this lecture. The above reasoning can be made more formal as follows.1. Thus. . . Therefore Qn+1 contains the accepting state qn+1 . There exists an NFA with n + 1 states that recognizes L. . Thus. Now we reason as follows. The transition function T ′ is defined as follows. . Qn+1 . Qi+1 = p∈Qi T (p. Q2 . σi ). n. This blow up is inevitable. . . Assume that w is accepted by A. The set of states S ′ of B is P (S). Qn+1 of subsets of S inductively as follows: Q1 = I. I. . Make s unmarked. The set F contains all states Q ∈ S such that Q′ has a final state of A. n. σ) = T (p. Define the sequence Q1 . σi ). q0 . 2. L is also DFA recognizable. Note that for every state q ∈ Qi+1 there exists a state p ∈ Qi such that q ∈ T (p. all we need to remember in order to process a given input signal σ is the states that are now marked. Note that each qi belongs to Qi . . Qn . σn be a string and A = (S. if Qn+1 contains an accepting state then A must have an accepting run on w. We have already shown that L(A) = L(B). . The above process (after reading σ1 ) marks several states of the automaton. Qn+1 = p∈Qn T (p. . T ′ (Q. F ′ ): 1. ′ The discussions above suggests the following construction of a machine B = (S ′ . Then there exists an accepting run q1 . Mark all states q if there is a transition from s to q labeled with σ1 . .. The construction of the DFA from a given NFA A provided above is known as subset construction. qn+1 such that qi+1 ∈ T (qi . . . It may be the case that s can be marked again because there could be a transition from s or another previously marked s′ to s labeled with σ1 . . . The machine B is clearly a DFA. T ′ . Each Qi is a subset of S. . p∈Q 4. . Our current memory is thus all the states that are now marked. . . . ′ 2. . σ). By the theorem above. there is an exponential blow up in the number of states of the input automaton A. Let w = σ1 . T. for all i = 1. Therefore for every state qn+1 ∈ Qn we can produce a sequence q0 . . Theorem 1. As an application of this theorem consider the language L={uav | u ∈ {a. Hence. 3. and so on. . The theorem is considered to be one of the important results in theoretical computer science and computability. . . . For any state Q ∈ S ′ (that is a subset of S) and any symbol σ ∈ Σ.

. With these transitions the machine does not process the input signal but rather prepares itself to process the signal. This continues on. I ⊂ S is the set of initial states. In the first case. 2. in the first case. . Once the entire string w is processed. Informally. In the second case. Again. At state s. The machine. In the second case. Denote by Σλ = Σ ∪ {λ}. At state q1 . Select nondeterministically a transition from q1 labeled with σ1 . Σλ ) such that: 1. the machine acts as an NFA. σi−1 part of the input string. 4. we say that A accepts the string w. I. it makes a silent move by changing its state only. call it q1 . that is it changes its state and reads the symbol and moves to the next symbol of the input string. Let Σ be an alphabet. an NFA with silent moves is defined as follows: Definition 5. Select nondeterministically a silent transition without reading the symbol σ1 . the automaton still needs to process the first symbol σ1 . It nondeterministically selects an initial state. Select nondeterministically a silent transition without reading the symbol σi . Assume that the automaton has arrived to state s and has processed σ1 . This move of the machine is sometimes called a silent move or silent transition. the automaton may have one of the following two possibilities: 1. instead of reading the next symbol σ. S is the finite set of states of A. 3. The meaning of λ-transitions is the following. we often use the term finite automata (FA) recognizable to mean either of these notions. Formally. We say that the run is accepting if the automaton can enter an accepting state after processing the entire string w. the automaton has two possibilities as above: 1. Recall that λ represents the empty string. 3 NFA with silent moves An NFA with silent moves is an NFA equipped with λ-transitions. F ⊂ S is the set of accepting states. T is a transition function T : S × Σλ → P (S). the automaton can still continue on running using its silent transitions. In state q the machine can either make a σ-transition or again repeat its silent move (if there is a silent transition from q). . . silent moves are internal transitions of the machine. 2. moves to q and thus changes its state from s to q. In the second case. In this case. . F. the automaton is ready to start processing the next input symbol σ2 .Since NFA and DFA recognizability are equivalent notions ( as we have proved). On input w = σ1 . An NFA with silent moves is a tuple (S. Select nondeterministically a transition from s labeled with σi . Assume that the machine is in state s and decides to move along a transition from state s to a state q labeled with λ. In the first case. A is now ready for processing the next input symbol σi+1 . σn ∈ Σ ⋆ the automaton A starts its run as follows. 2. the automaton still needs to process the first symbol σi . T.

Take an accepting run (⋆) s1 . using the definition of T ′ . . . Inductive Step k + 1. 1 2 3 4 n−1 n n+1 of A on w. . Assume that w = σ1 . 2. . . . s′ . Clearly B is an NFA that does not have λ-transitions. . . . ∪ SilentM ovesn(s). F ) with silent moves can be simulated by an NFA without silent moves. . SilentM oves0(s) = {s}. 4. F ′ = {q | SilentM oves(q) ∩ F = ∅}. . sn−1 . 1 from state s2 the automaton A makes zero or more silent transitions to state s′ at which A 2 selects a σ2 -transition to state s3 . Define SilentM oves(s) recursively as follows: Base case. . . . s′ . We want to show that the automaton A accepts w. Assume now that w = σ1 . sn+1 . T. We now construct the following automaton B = (S ′ . s4 . . . . . sn+1 of B on w. sn . s′ . Let s be a state of A = (S. . . . s′ . then the automaton. by moving along the λ-transitions. . s′ . . SilentM oves(s) is the collection of all states that are reachable from the state s using the λ-transitions. . . . 3. By the definition of T ′ . . Thus. s′ . . s3 . . sn+1 . If the automaton is in state s and the next symbol is σ. . σ). s2 . T ′ . . s′ . σn is accepted by the NFA B. . the automaton A makes zero or more silent transitions to a state s′ at which A selects a σ1 -transition to state s2 . . . Define SilentM oves(s) = SilentM oves0(s) ∪ SilentM oves1(s) ∪ . . s2 . . . . s′ . this means A can make 0 or more silent transitions to reach a final state in A. . . Then. . σn is accepted by the NFA A. . . We want to show that the automaton A with silent moves and the automaton B without silent moves are equivalent. . I. s′ . . Take an accepting run s1 . . S ′ = S. s′ . . F ). 1 2 3 4 n−1 n Since sn+1 is the final state of B. . s4 . . . . This continues on. I. where n is the number of states in the automaton A. This shows that A accepts the string w. I ′ . . by the definition of I ′ . . F ′ ): 1. s′ . . can select any of the states q in SilentM ove(s) and move along a transition labeled by σ from q. σ) = q∈SilentMoves(s) T (q. we can build a run of A: s1 . . T. . The transition function T ′ is defined above.Our goal is to show that every nondeterministic automaton A = (S. I ′ = I. For this run we have the following properties: . . s′ . . . s1 is an initial state of A. s′ . Thus. Set SilentM ovesk+1 (s) = SilentM ovesk (s) ∪ {q | there is a silent transition from some p ∈ SilentM ovesk (s) to q}. . . . s3 . we can modify the transition function T of A as follows: T ′ (s. sn . Again. . Therefore. Assume we have defined SilentM ovesk (s). .

decides whether A accepts any string at all. . . The accepting run is simply a path from the initial state s1 to the final state sn . Here is now a description of the algorithm that solves the emptiness problem. 2. 3. n. For each i. suppose that there exists a path from some initial state to some final state: s1 . . The state sn+1 ∈ F ′ . Conversely. I. We recall that a state s in an automaton is non-deterministic if there are more than one transitions from s labeled with the same input symbol. From the properties above and the construction of B we have the following.. The problem is easy to solve by noticing the following. The following statements are equivalent: 1. σn be the labels of the edges (s1 .1. 4 Algorithmic problems for finite automata In this section we present algorithms for solving several natural problems about finite automata. Thus. . B has an accepting run on w. We have already dealt with several algorithms manipulating automata. . A accepts a string if and only if there exists a path from some initial state in I to a final state in F . and complementation operations. si+1 ∈ T (s′ . (sn . . This problem asks to design an algorithm that. the part si . There exists an NFA with silent moves recognizing L. . . In the two sections above we dealt with construction of automata such as the subset construction. In this section we describe some other interesting problems about automata and their solutions. The emptiness problem. Let L be a language. s′ n+1 ∈ F . n + 1. i 3. . . . . . The state s1 is an initial state of B. and the construction that transforms NFA with silent moves to NFA without silent moves. We also studied the minimization algorithm. σn is a string accepted by A. This problem is interesting because many problems in systems verification and program design can be reduced to the emptiness problem for automata. . . F ) be a finite automaton. s1 is an initial state of A. 2. . For each i = 1. σi ). s2 . Then σ1 . sn+1 Let σ1 . . n. union. . Let A = (S. . . . s2 ). . si+1 ∈ T ′ (si . s′ of the run in (⋆) is due to silent moves of the i automaton A. Note that A is not restricted to be deterministic. There exists an NFA recognizing L. There exists a DFA recognizing L.. . If A accepts a string w then A has an accepting run s1 . we state the following theorem: Theorem 2.. given a finite automaton A. sn on w. . we have shown that NFA with silent moves are equivalent to NFA without silent moves. Gathering the results of this and the previous section. T. Thus. sn+1 ). . σi ). Thus. . In the previous lecture we provided algorithms for constructions of deterministic finite automata for the intersection. . s2 . For each i = 1. 4. .

this problem has a straightforward solution described as follows. decides whether the automaton A recognizes Σ ⋆ . Here we describe one of the algorithms called the Equivalence(A. If L(B1 ) = ∅ then output “A and B are not equivalent”. and otherwise not. respectively. Finally. If A and B are deterministic then the algorithm is quite efficient because there is no need to run the subset construction. output “A and B are equivalent”. we check if L(A(c) ) = ∅. If an NFA has n states then the subset construction produces a DFA with 2n states. This problem asks to design an algorithm that. This solves the emptiness problem for automata. 5. Construct two deterministic finite automata A(c) and B(c) that recognize the complement of L(A) and L(B). Comment: From now on we assume that A and B are deterministic. t) algorithm from Lecture 3). This is exactly what the algorithm above detects. As in the solution of the equivalence problem. 3. If L(A(c) ) = ∅ then A recognizes Σ ⋆ . This algorithm is correct because A and B are equivalent if and only if L(A) \ L(B) = ∅ and L(B) \ L(A) = ∅. 2. We construct the automaton A(c) that recognizes the complement of the language L(A). This produces a directed graph G. If B has nondeterministic states then apply the subset construction to B. If A has nondeterministic states then apply the subset construction to A. The subset construction produces deterministic finite automata. our solution here involves the subset construction that slows down the efficiency of the algorithm significantly. Therefore it takes an exponential amount of time with respect to the numbers of states of the input automata A and B to execute the first step of the algorithm. given finite automata A and B. Comment: A1 recognizes the language L(A) \ L(B) and B 1 recognizes L(B) \ L(A). If for some s ∈ I and t ∈ F there is a path from s to t then A accepts at least one string. Otherwise. We note that the first step of the algorithm uses the subset construction. This problem asks to design an algorithm that. A accepts no string. B) algorithm: 1. If L(A1 ) = ∅ then output “A and B are not equivalent”. The equivalence problem. So. s. There are several algorithms to solve this problem. respectively. Construct two deterministic finite automata A1 and B1 that recognize the languages L(A) ∩ L(B(c) ) and L(B) ∩ L(A(c) ). and then stop. If A has nondeterministic states then we apply the subset construction to A. As the previous problems. and then stop. For states s ∈ I and t ∈ F check if there is a path from s to t (This can be done using the P athExistence(G. decides whether these automata are equivalent.Remove the labels from the edges of the transition diagram of the automaton A. If we think of A and B as finite state descriptions of two programs then this problem asks whether these two programs simulate each other. . we can now assume that A is a deterministic finite automaton. 4. The universality problem. Otherwise. given a finite automaton A.

. . the automaton exhausts its memory capacity and has to reuse one of its states that has already been used. sm+1 ˜ is an accepting run of the automaton A on the input σ1 . . where v is σi . σi−1 v t σi+k+1 . We solve this problem in the next section after explaining a result known as the pumping lemma. . I. . sm . σm . Lemma 1 (The Pumping Lemma). si . st . given a finite automaton A. σm . F. . s2 . σm be a string from Σ ⋆ such that m ≥ n. T. . . The key point here is that at least two states in the sequence s1 . . The reason for this is that the automaton has a fixed amount of memory. Therefore there must exist a state in this run that is repeated. . there exists a run s1 . We now can ¯ ¯ conclude that for any integer t ≥ 0 the sequence s1 . Therefore the segment of the computation between any two repeated states can be performed any number of times without effecting the outcome of the run. . . σi+k . σm such that sm+1 ∈ F . . This problem asks to design an algorithm that. Let s be the sequence of states: ¯ si+1 . a finite number of states. Let A = (S. . Hence there exist i and i + k both less than or equal to m + 1 such that si = si+k and k = 0. . . σi+k of the string w such that for all t ≥ 0. . sm+1 must be the same since n is the number of states and m + 1 > n. σi−1 v t σi+k+1 . . . . s2 . . This proves the lemma. si−1 . Σ) be an NFA with exactly n states. the automaton A accepts the string σ1 . . si+k . Hence while making a long run. . If A accepts the string w then there exists a nonempty substring v = σi . decides whether the automaton accepts infinitely many strings. . . . Since A accepts w. . . . Recall that st denotes the concatenation of the sequence s with itself t times. . . . . sm . 5 The pumping lemma The essence of the pumping lemma is that any sufficiently long run of an automaton must have repeated states during the computation. sm+1 of the automaton on the input w = σ1 . Proof. si+k+1 . .The infinity problem. . . Let w = σ1 . . In order to solve this problem we need to have a finer analysis of the transition diagrams of automata. that is.

The Pumping Lemma and its proof can be applied to obtain some interesting results. . Then. Otherwise. we can split u into three pieces u = xyz such that |y| ≥ 1 and for all t ≥ 0 the string xy t z is in L. Construct the set X = {q | q is a looping state }. s. assume that in the transition diagram of the NFA A there exists a path from an initial state to a looping state. From the proof of the Pumping lemma. sm+1 of A on w with the following properties: 1. This string satisfies the hypothesis of the pumping lemma (it is accepted by A and its length is greater than the number of states of A). s1 is an initial state and sm+1 is a final state. . . . we now provide an algorithm that solves the infinity problem. . and from the looping state to a final state. si+k a loop and si a looping state. Transform A into an NFA with no silent transitions. . Let A be a finite automaton with k states that recognizes L. Check if there exist paths from an initial state s to a state q ∈ X and from q to a final state. Here is now the Inf inity(A) algorithm that solves the infinity problem. Consider the string u = ak bk . t) algorithm. Comment: This set can be constructed using the P athExistsence(G. Thus. . we see that there exists a run s1 . Assume to the contrary that this language L is FA recognizable. 2. To design an algorithm that detects whether an automaton A accepts infinitely many strings we observe the following. 2. Thus. Then there exists a string w accepted by A such the length of w is greater than the number of states in A. of course. . b} is not FA recognizable. . Now suppose that L(A) is an infinite language. But by the pumping lemma xyyz is in L. by the Pumping lemma. Now there are three cases to be considered. Therefore L(A) is an infinite language. A typical example is an elegant proof that the language L = {an bn | n ∈ N } over the alphabet {a. 1. As an example. 3. We already discussed this language in the previous lecture and gave an informal reasoning why L is not FA recognizable. Now take a string u2 that labels a path from the looping state to the final state. output “L(A) is finite”. The pumping lemma can also be applied to prove that certain languages are not FA recognizable. if L(A) is infinite then the automaton A has the following properties. There exists a path from an initial state to a looping state and from the looping state to an accepting state. If there is such paths then output “L(A) is infinite”. Indeed. where t ≥ 0. There exist i and i + k with k = 0 such that si . Therefore. say q. Then it is easy to see that L(A) accepts infinitely many strings. . Since q is a looping state there must exist a nonempty string v that labels a path from q to itself. The string y contains a’s only. . We call the sequence si . si+k is a path and si = si+k . . we have that the strings u1 v t u2 are all accepted by A. We first assume that A does not have silent transitions (by applying the construction from the previous section that removes all the λ-transitions). Conversely. . Here is now a formal proof of this fact. sm . we take a string u1 that labels the path from the initial state to the looping state. the string xyyz is not in L. Case 1. This is a contradiction. the string xyyz has more a’s than b’s in it. s2 . By the definition of L.

7. Let A = (S. – Inductive step n + 1. Case 3. Set Sn+1 = Sn {T ′ (Xi . Again. . Prove that every NFA A is equivalent to an NFA with one initial state and one final state. 10. we have a contradiction. . Draw transition diagrams of NFA with specified number of states that recognize languages provided. 12. Write a program that implements the algorithm. σ). 4. Set S ′ = Sk . 11. B) algorithm. Implement the Equivalence(A. checks if A accepts w. 3. T. X F = ∅}. The alphabet is {a. I. σ) = p∈Q T (p. The language P ref ix(W ) is the set of all strings that are prefixes strings from W . 8. 1 ≤ i ≤ k}. b}⋆ and the length of v is n}. this is again a contradiction. Show that A′ is a deterministic automaton that is equivalent to A. where T ′ (Q. . then the string xyyz must have some b’s before a’s. Prove the following two facts. Well. Construct a new set S ′ by induction as follows. All these cases show that A cannot recognize L. Prove that if W is FA recognizable then so is P ref ix(W ). Prove that if W is FA recognizable then so is W ⋆ . But by the pumping lemma the string xyyz is in L. P ref ix(W ) = {u | u is a prefix of a string from W }. Design an algorithm that given an NFA A (which may be with silent moves) and a string w. (5 states) (d) {w | w ends with an a and no a occurs between any occurrences of b} (2 states) 2. The string y contains both some a’s and some b’s. (a) There exists an n such that Sk+1 = Sk . . Formally. T ′. σ) | σ ∈ Σ. F ′ ). 9. Set S0 = {I}. (b) Set F ′ = {X|X ∈ S ′ . For each natural number n ≥ 1 consider the language Ln = {uav | u ∈ {a. 6. Write a program Determinize(A) that given an NFA A outputs a DFA B equivalent to A. . {I}. Let W be a language. The string y contains b’s only. b} (a) {w | w ends with 000}. F ) be an NFA. 6 Exercises 1. – Base case. As in Case 1. Write a program that solves the emptiness problem. Write a program T ransf orm(A) that given an NFA A with silent moves outputs an NFA B (without silent moves) equivalent to A. Define A′ = (S ′ . 5. Hence L is not FA recognizable. (9 states) (c) {w | w contains substring abab}. Prove that if W and U are FA recognizable then so is W · U . (4 states) (b) {w | w contains a substring aub such that u has length 6}. Suppose that Sn has been built and is {X1 . Then such a string is not in L by the definition of L. Xk }. where Sk = Sk+1 .Case 2. Prove that no DFA with less than 2n states recognizes Ln .

(b) If L ⊆ Σ ⋆ is FA recognizable then L is a finite union of ultimately periodic languages. 16. an+2p . Show that the language {an bn cn | n ∈ ω} is not FA recognizable. Show that the language {ww | w ∈ {a. an+3p .13. Write a program that solves the universality problem. Show that the language {w | w has an equal number of a’s and b’s } is not FA recognizable. 14.}. . . an+p . 18. b}⋆ } is not FA recognizable. Consider the unary alphabet Σ = {a}. Implement the Inf inity(A) algorithm. Prove the following: (a) Every ultimately periodic language is FA recognizable. A language L of this alphabet is called ultimately periodic if there are natural numbers n and p ≥ 0 such that L = {an . . 15. 17. .