{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# ch3 - ELEMENTS OF COMPUTATION THEORY Chapter 3...

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

Undergraduate Course ELEMENTS OF COMPUTATION THEORY College of Computer Science Chapter 3 ZHEJIANG UNIVERSITY Fall-Winter, 2007 P 120-122 3.1.3 Construct CFGs that generate each of these languages. ( c ) { w ∈ { a, b } * : w = w R } . Solution: ( c ) G = ( V, Σ , R, S ) , where: V = { a, b, S } Σ = { a, b } R = { S aSa, S bSb, S a, S b, S e } . 3.1.9 Show that the following languages are context-free by exhibiting CFGs generating each. ( a ) { a m b n : m n } ( b ) { a m b n c p d q : m + n = p + q } Solution: ( a ) G = ( V, Σ , R, S ) , where: V = { a, b, S } Σ = { a, b } R = { S aSb, S aS, S e } .

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

View Full Document
( b ) Let m + n = p + q = N , then n = N - m , p = N - q . a m b n c p d q = a m b N - m c N - q d q In case of m q , a m b n c p d q = a q a m - q b N - m c N - m c m - q d q Therefore, we can obtain CFG G = ( V, Σ , R, S ) , where: V = { a, b, c, d, S, A, B } Σ = { a, b } R = { S aSd , S A , A aAc , A B , B bBc, B e } In case of m < q , we can obtain the similar results. P 135 3.3.2 Construct pushdown automata that accept each of the following. ( c ) The language { w ∈ { a, b } * : w = w R } . ( d ) The language { w ∈ { a, b } * : w has twice as many b ’s as a ’s } . Solution: ( c ) M = ( K, Σ , Γ , Δ , s, F ) , where: K = { q, r } Σ = { a, b } Γ = { a, b } F = { r } Δ = { (( q, a, e ) , ( q, a )) (( q, b, e ) , ( q, b )) (( q, e, e ) , ( r, e )) (( q, a, e ) , ( r, e )) (( q, b, e ) , ( r, e )) (( q, a, a ) , ( r, e )) (( q, b, b ) , ( r, e )) }
( d ) M = ( K, Σ , Γ , Δ , s, F ) , where: K = { q } Σ = { a, b } Γ = { A, a, b } F = { q } Δ = { (( q, a, e ) , ( q, A )) (( q, b, e ) , ( q, b )) (( q, a, b ) , ( q, a )) (( q, b, A ) , ( q, a )) (( q, b, a ) , ( q, e )) } P142 3.4.1 Carry out the construction of Lemma 3.4.1 for the grammar of Example 3.1.4. Trace the operation of the automaton you have constructed on the input string (()()). Solution: The new machine is M = ( { p, q } , { ( , ) } , { ( , ) , S } , Δ , p, { q } ) , where Δ = { (( p, e, e ) , ( q, S ) , (( q, e, S ) , ( q, SS )) , (( q, e, S ) , ( q, ( S ))) , (( q, e, S ) , ( q, e )) , (( q, ( , () , ( q, e )) , (( q, ) , )) , ( q, e )) } Then ( p, (()()) , e ) M ( p, (()()) , S ) M ( p, (()()) , ( S )) M ( p, ()()) , S )) M ( p, ()()) , SS )) M ( p, ()()) , ( S ) S )) M ( p, )()) , S ) S )) M ( p, )()) , ) S )) M ( p, ()) , S )) M ( p, ()) , ( S )))

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

ch3 - ELEMENTS OF COMPUTATION THEORY Chapter 3...

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

View Full Document
Ask a homework question - tutors are online