hwsoln05

hwsoln05 - CS 341 Foundations of Computer Science II Prof...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 341: Foundations of Computer Science II Prof. Marvin Nakayama Homework 5 Solutions 1. Give context-free grammars that generate the following languages. (a) { w ∈ { , 1 } ∗ | w contains at least three 1 s } Answer: G = ( V, Σ ,R,S ) with set of variables V = { S,X } , where S is the start variable; set of terminals Σ = { , 1 } ; and rules S → X 1 X 1 X 1 X X → X | 1 X | ε (b) { w ∈ { , 1 } ∗ | w = w R and | w | is even } Answer: G = ( V, Σ ,R,S ) with set of variables V = { S } , where S is the start variable; set of terminals Σ = { , 1 } ; and rules S → S | 1 S 1 | ε (c) { w ∈ { , 1 } ∗ | the length of w is odd and the middle symbol is } Answer: G = ( V, Σ ,R,S ) with set of variables V = { S } , where S is the start variable; set of terminals Σ = { , 1 } ; and rules S → S | S 1 | 1 S | 1 S 1 | (d) { a i b j c k | i, j,k ≥ , and i = j or i = k } Answer: G = ( V, Σ ,R,S ) with set of variables V = { S,W,X,Y,Z } , where S is the start variable; set of terminals Σ = { a,b, c } ; and rules S → XY | W X → aXb | ε Y → cY | ε W → aWc | Z Z → bZ | ε 1 (e) { a i b j c k | i, j,k ≥ and i + j = k } Answer: G = ( V, Σ ,R,S ) with set of variables V = { S,X } , where S is the start variable; set of terminals Σ = { a,b,c } ; and rules S → aSc | X X → bXc | ε (f) ∅ Answer: G = ( V, Σ ,R,S ) with set of variables V = { S } , where S is the start variable; set of terminals Σ = { , 1 } ; and rules S → S Note that if we start a derivation, it never finishes, i.e., S ⇒ S ⇒ S ⇒ ··· , so no string is ever produced. Thus, L ( G ) = ∅ . (g) The language A of strings of properly balanced left and right brackets: ev- ery left bracket can be paired with a unique subsequent right bracket, and every right bracket can be paired with a unique preceding left bracket. More- over, the string between any such pair has the same property. For example, [[]] ∈ A . Answer: G = ( V, Σ ,R,S ) with set of variables V = { S } , where S is the start variable; set of terminals Σ = { [ , ] } ; and rules S → ε | SS | [ S ] 2. Let T = { , 1 , ( , ) , ∪ , ∗ , ∅ , e } . We may think of T as the set of symbols used by regular expressions over the alphabet { , 1 } ; the only difference is that we use e for symbol ε , to avoid potential confusion in what follows....
View Full Document

This note was uploaded on 01/22/2011 for the course CIS 341 taught by Professor Nakayama during the Fall '10 term at NJIT.

Page1 / 7

hwsoln05 - CS 341 Foundations of Computer Science II Prof...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online