hw2sol

# hw2sol - CSE 105 Introduction to the Theory of Computation...

This preview shows pages 1–4. Sign up to view the full content.

CSE 105: Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao Solution to Problem Set 2 February 14, 2003 Solution to Problem Set 2 2.1 Given the grammar G : E E + T | T T T × F | F F ( E ) | a Give the parse trees and derivations for each string. a. The derivation is E T F a . The parse tree is shown in Figure 1. b. The derivation is E E + T T + T F + T a + T a + F a + a . The parse tree is shown in Figure 1. c. The derivation is E E + T E + T + T T + T + T F + T + T a + T + T a + F + T a + a + T a + a + F a + a + a . The parse tree is shown in Figure 1. d. The derivation is E T F ( E ) ( T ) ( F ) (( E )) (( T )) (( F )) (( a )). The parse tree is shown in Figure 1. E E T F a + T F a E T F a T F a E T F E T F E T F E T F a E T F a + E + a ( ) ( ) Figure 1: 2.1 (a), (b), (c), and (d) 2.3 The given context-free gramar G is 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CSE 105, Solution to Problem Set 2 2 R 7→ XRX | S S 7→ aTb | bTa T 7→ XTX | X | ² X 7→ a | b a. The variables of G are { R,X,S,T } . The terminals of G are { a,b } . The start variable is R . b. Strings in L ( G ) are ab , ba , and aaaabbaaa . c. Strings not in L ( G ) are aaa , aba , and bb . d. T aba : false. e. T * aba : true. f. T T : false. g. T * T : true. h. XXX * aba : true. i. X * aba : false. j. T * XX : true. k. T * : false. l. S * ² : false m. The language generated by L is the language of all strings w over { } such that w is not palindrome, that is, w 6 = w R . 2.6 b. L is the complement of the language { a n b n : n 0 } . First, let’s see what the complement of L looks like: L = { a n b m : n 6 = m } ∪ { ( a b ) * ba ( a b ) * } Let’s call the leftmost language L 1 and the rightmost L 2 . The context-free grammar that generate L 1 is S 1 aS 1 b | T | U T aT | a U Ub | b The context-free grammar that generate L 2 is S 2 RbaR R RR | a | b | ² Therefore, the context-free grammar G that generate L = L 1 L 2 is S S 1 | S 2 S 1 aS 1 b | T | U S 2 RbaR T aT | a U | b R RR | a | b | ²
CSE 105, Solution to Problem Set 2 3 c. L = { w # x : w R is a substring of x for w,x ∈ { 0 , 1 } * } . The context-free grammar G that generate L is S TR T 0 T 0 | 1 T 1 | # R R RR | 0 | 1 | ² 2.7 a). The language of strings over the alphabet { a,b } with twice as many a ’s as b ’s. The PDA that recognizes this language is shown in Figure 2. a , h ² ²,² h \$ ², \$ ² q 0 q 1 q 2 q 3 q 4 q 5 q 6 q 7 q 8 b , \$ \$ b h h ², \$ ² a , \$ \$ a b , a ² ², a ² a a a a b h Figure 2: 2.7 (a) d). L = { x 1 # x 2 ··· # x k | k 1, each x i ∈ { } and for some i and j , x i = x R j } .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

hw2sol - CSE 105 Introduction to the Theory of Computation...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online