Vous êtes sur la page 1sur 4

Solution to CS243 Assignment3

1. Text (Sipser, second edition) Chapter 2 (p.128) 2.4 2.4b S 0 | 1 | 0R0 | 1R1 R 0R | 1R | 2.4c S 0T | 1T T 0S | 1S | 2.4e S | 0 | 1 | 0S0 | 1S1 2.4f (V, , , S), where V={S}, and = {0,1} 2. Text (Sipser, second edition) Chapter 2 (p.129) 2.6bd 2.6b SR|T|W W ba | XW | WX (out of order) Xb|a R a | aR | aRb (in order, but more a) T b | Tb | aTb (in order, but more b) 2.6d S R#Y | Y#R | Y Y | a | b | aYa | bYb | a#R#a | b#R#b (xi = xjR occurs in Y) R R#X | X (any number of strings) X aX | bX | (any string) 3. Text (Sipser, second edition) Chapter 2 (p.129) 2.9 S AR | TC A aA | C cC | R bRc | T aTb | This CFG is ambiguous. It has two derivation for abc: abc abc | | AR TC / \ / \ aR bRc aTb cC | | | |

4. Text (Sipser, second edition) Chapter 2 (p.130) 2.20 Proof idea: Let NB be the NFA for the language B. We can construct the following PDA to recognize A\B. This PDA non-deterministically enters NB, and move within NB based on what is on the stack top: (1) if its a symbol a, then move to qk = B(qi,a); (2) if its a variable V, then replace the stack top with string y, based on rules specified in the CFG of language A. It can be seen that if the PDA end up in the accept state for input string w, there must exist a string x in B so that wx is in A. Thus this PDA recognize the language A\B, i.e., A\B is CFL.

, S$

, Vy a, a

NB

q0

, Vy

.
, Vy , a qi
qk

, Vy

.
, Vy
F

, $

5. Text (Sipser, second edition) Chapter 2 (p.130) 2.26 Proof by induction on |w|, the length of the string. Basis: |w|=1, it takes 2*1 1 = 1 step: S a. Hypothesis: Lets assume 2k 1 steps required for any string with length k < n. For |w|=n : S AB is first derivation, where A and B are corresponding to wA and wB respectively, where w=wAwB. Based on our induction hypothesis, for wA, it takes 2kA 1 steps of derivation starting from A, where kA = |wA| < |w| = n. Similarly, it take 2kB 1 steps of derivation starting from B for wB, where kB = |wB| < |w| = n. Thus it takes 1 + (2kA 1) +(2kB 1) = 2(kA+ kB) 1 = 2|w| 1 = 2n 1 steps of derivation for w. 6. Text (Sipser, second edition) Chapter 2 (p.131) 2.30ad 2.30a Assume the language is CFL. Let p be the pumping length given by pumping lemma for this CFL. Let s = 0p1p0p1p, then s can be divided into five parts as s = uvxyz, where |vxy| p. So, vxy can only occur in 0p1p (first half of s), 1p0p or 0p1p (second half of s). If vxy occurs in 0p1p (first half of s), then uvvxyyz will either have more 0s or 1s in the first half than the second half. So, uvvxyyz is not a string in the language. If vxy occurs in 1p0p, then uvvxyyz either has more 1s in first half then the second half or has more 0s in second half than the first half. If vxy occurs in 0p1p (second half of s), then uvvxyyz will either have more 0s or 1s in the second half than the first half. So, uvvxyyz is not a string in the language. Thus, the language is not a CFL. 2.30d Assume the language is CFL. Let p be the pumping length given by pumping lemma for this CFL. Let s = apbp#apbp, then s can be divided into five parts as s = uvxyz, where |vxy| p. Case 1: vxy in one of apbp, then uv0xy0z has less as or/and bs in one side of # than the other. Thus uv0xy0z is not in the language. Case 2: if vxy is contained in bp#ap, uv0xy0z has less bs on the left side and less as on the right side. Thus uv0xy0z is not in the language. Thus the language is not CFL. 7. Text (Sipser, second edition) Chapter 2 (p.131) 2.33 Assume the language F is CFL. Let p0 be the pumping length given by pumping lemma for this CFL. Let s = appbp, where p > p0. Then s can be divided into five parts as s = uvxyz, where |vxy| p0 < p. Case 1: Both v and y contains only as. Since k = |vy| |vxy| < p and k = |vy| >0, uv0xy0z = appkbp, where p2p < pp k < p2 since 0< k = |vy| p. It can be seen that ppk cannot be a multiple of p, since there is no integer within the range (p1, p). Thus uv0xy0z is not in F. Case 2: Both v and y contains only bs. Let k= |vy| >0, then uvixyiz = appbp+ik. Since p+ik >

pp for any i > p2. Thus uvixyiz, where i > p2, is not in F. Case 3: One of v or y contains both as and bs. Then as and bs in uvixyiz are out of order, and of course cannot be in F. Case 4: v contains only as and y contains only bs. Let v = ah, and y = bk, where it must be h>0, otherwise it is the same as Case 2 because |x|=0. Also, it must be k>0, otherwise it will become the same as Case 1. For uvixyiz = app+ihbp+ik, where h>0 and k>0, the ratio is f(i) =(p2+i*h)/(p+i*k). Since the first derivative of f(i) is f'(i) = (h*pp2)/(p+k*i)2 < 0 (notice that h<p, because k>0). Thus f(i) is a decreasing function in the range of (h/k, f(0)], where
i +

lim

p2 + i * h h = p + i*k k

However, there are less than f(0) = p integers in the range (h/k, p], and f(i) is a decreasing function. Thus, only for a limited number of i, f(i) is integer. That is, we can always find an i, so that (p2+i*h)/(p+i*k) is not integer, and uvixyiz is therefore not in F.

Vous aimerez peut-être aussi