0% found this document useful (0 votes)
306 views4 pages

Automata Theory - Homework II (Solutions) : 1 Problems

This document provides solutions to homework problems on automata theory. It discusses regular languages and grammars, proofs using the pumping lemma, ambiguous grammars, and removing unnecessary productions from grammars. Specifically, it shows how to construct a right-linear grammar for a regular language, proves a language is not regular using the pumping lemma, gives an example of an ambiguous grammar and language, and describes removing lambda productions, unit productions, and useless productions from a grammar.

Uploaded by

Mondar Deb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
306 views4 pages

Automata Theory - Homework II (Solutions) : 1 Problems

This document provides solutions to homework problems on automata theory. It discusses regular languages and grammars, proofs using the pumping lemma, ambiguous grammars, and removing unnecessary productions from grammars. Specifically, it shows how to construct a right-linear grammar for a regular language, proves a language is not regular using the pumping lemma, gives an example of an ambiguous grammar and language, and describes removing lambda productions, unit productions, and useless productions from a grammar.

Uploaded by

Mondar Deb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Automata Theory - Homework II (Solutions)

K. Subramani LCSEE, West Virginia University, Morgantown, WV {[email protected]}

1 Problems
1. Let L be a regular language not containing . Argue that there exists a right-linear grammar for L, whose productions are restricted to the forms: A A aB, and a

where A and B are generic variables and a is a generic terminal. Solution: In class, we showed that every regular language can be represented as a DFA M = Q, , , q0 , F , where the symbols should be interpreted using the standard convention. Since, L is -free, it must be the case that q0 F . We construct the following Right-Linear Grammar G = V, T, S, P for L: (a) We use symbol Ai to denote state qi . V = {Ai : i = 0, 1, . . . , |Q| 1}. (b) The set of terminals T is precisely . (c) S = A0 . (d) The productions P of G are dened as follows: For each transition, (qi , a) = qj , add the production Ai aAj . If qj is also a nal state, then add the production Ai a. We use induction on the number of transition steps to show that if (q0 , w) F , then A0 w. Likewise, we use induction on the number of steps in a leftmost derivation to establish that if A0 w, then (q0 , w) F . (The induction proofs are straightforward exercises). 2 2. Consider the language L = {an : n is not a perfect square}. Prove that L is not regular, by using the Pumping Lemma. You may not use complement properties of regular languages. Solution: One way of showing that L is not regular is through the following argument: If L is regular, then so is Lc ; however, we showed in class that Lc is not regular and hence L cannot be regular. Since you were expressly forbidden from using the complement properties of regular languages, let us proceed to prove the non-regularity of L, using rst principles. Assume that L is regular and let M = Q, , , q0 , F denote the unique minimal state DFA for L, where the symbols in the tuple have their usual meaning. Let p denote the number associated by the Pumping Lemma with L; we know 2 that p = |Q|. Let G = {ap +i : i = 1, 2, . . . 2p}; we can think of the strings in G as being indexed by their length 2 after subtracting the offset p2 . Using wi to refer to the string ap +i , we have that |wi | + 1 = |wi+1 |. Let R = {(q0 , wi ) : wi G}; we use ri to denote (q0 , wi ), wi G. The following observations are in order: (i) All the states in R are nal states.

(ii) |G| = 2p and |R| p. As per the pigeonhole principle, there must exist at least two strings wi and wj in G, such that (q0 , wi ) = (q0 , wj ) = rk , rk R. We have thus established that there exists a string as , 1 s p, and a state rk R, such that (rk , as ) = rk . Let T = {(rk , a), (rk , a2 ), . . . , (rk , as1 ), (rk , as )}; clearly T R. T represents a cycle of nal states on a-transitions; it follows that the DFA can never escape from this cycle towards a non-nal state on a-transitions. Thus 2 2 2 (q0 , ap +2p+1 ) T ; however, ap +2p+1 = a(p+1) and should be rejected by the DFA M . We thus have the desired contradiction and it follows that L cannot be a regular language. 2 3. Consider the grammar G = V, T, S, P , with productions dened by: S aSbS | bSaS | Is G ambiguous? Is L(G) ambiguous? Solution: G is ambiguous, since the string w = abab has two distinct leftmost derivations: (i) S aSbS abSaSbS abaSbS ababS abab, and (ii) S aSbS abS abaSbS ababS abab. L(G) is the language of strings over {a, b}, in which the number of as is equal to the number of bs. An unambiguous grammar for this language is given by: G = V, T, S, P , where, (a) V = {S}, (b) T = {a, b}, (c) S = S, and (d) P is dened by: S aSb | bSa | S S | You are required to use induction on the number of steps of a leftmost derivation from S to establish that if S w, lm then the leftmost derivation of w is unique. 2 4. Show that the language L = {w wR : w {a, b} } is not inherently ambiguous. Hint: Prove that L has an unambiguous grammar. Solution: An unambiguous grammar for L is G = V, T, S, P , where, (a) V = {S}. (b) T = {a, b}. (c) S = S. (d) The productions P are dened by: S aSa | bSb |

In order to establish the unambiguous nature of G, we need to show that for every string w L(G), there is precisely one leftmost derivation S w; this is done by using induction on the length of w. Before commencing the proof, lm we need the following lemmata. Lemma 1.1 If S w, then |w| is even. lm Proof: Exercise. Use induction on the number of steps in the shortest leftmost derivation of w. 2

Lemma 1.2 If w L, then the string w obtained by dropping the rst and last symbols of w, also belongs to L Proof: It is a straightforward observation (Use contradiction!). 2 Theorem 1.1 If S w, then this derivation is unique. lm Proof: We use induction on the length of w; the induction will be on the set of even numbers and not on the set of natural numbers (which is our conventional ground set). If |w| = 0, then w must be , and there is precisely one production rule and hence one way for w to be derived from S, in leftmost fashion. Assume that Theorem (1.1) is true, for all even-length strings of length at most 2 k, k 0. Now consider a string w L, of length 2 (k + 1). Since w L, it must be the case that w = axa or w = bxb, with x L (See Lemma (1.2)). However, |x| = 2 k and hence x has a unique leftmost derivation from S. It therefore follows that w has a unique leftmost derivation; for instance, if w = axa, then S lm aSa axa represents the unique lm leftmost derivation of w from S. A similar argument holds when w = bxb; we can therefore apply the principle of mathematical induction to conclude that every string in L has a unique leftmost derivation from S, i.e., G is unambiguous. Inasmuch as L has an unambiguous grammar, it follows that L itself is unambiguous. 2 2 5. Remove all unit productions, -productions and useless productions from the the grammar G = V, T, P, S , with productions P dened by: S aA | aBB aaA | bB | bbC B A B C

Solution: It is important that all -productions are deleted rst, followed by the unit productions and nally by the useless productions. If this order is altered, language preservation is not guaranteed [Lin06]. (a) Removing -productions - The only nullable symbol is A; accordingly, applying the algorithm in [Lin06], the removal of -productions results in the following set of productions: S aA | aBB | a aaA | aa bB | bbC B A B C

(b) Removing unit productions - There is precisely one unit production, viz., C B. Applying the algorithm in [Lin06], the removal of this unit production results in the following set of productions: S aA | aBB | a aaA | aa bB | bbB

A B

(c) Removing useless productions - Observe that no terminal string can be derived from B; it follows that any production involving B can be deleted, without affecting the language of the grammar. Accordingly, the nal set of productions is: S A 2 3 aA | a aaA | aa

References
[Lin06] Peter Linz. An Introductionto Formal Languages and Automata. Jones and Bartlett, 4th edition, 2006.

You might also like