cs381-fall02-prelim2-solutions - CS381 Fall 2002 Second Mid...

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

View Full Document Right Arrow Icon
CS381 Second Mid Term Friday Nov 8, 2002 Fall 2002 Olin 155 9:05-9:55 This is a 50-minute in class closed book exam. All questions are straightforward and you should have no trouble doing them. Please show all work and write legibly. Thank you. 1 . (a) Give a context-free grammar for the language } ' ' * ) ( | { s b and s a of number equal an has x and b a x x + (b) For each variable in the grammar describe the strings that can be generated from the variable by a statement such as s b and s a of number equal an has x iff x S ' ' Solution : bSa aSb SS S | | | ε s b and s a of number equal an has x iff x S ' ' Clearly any string generated has an equal number of a’s and b’s since the righthand side of each production has an equal number of a’s and b’s. Thus, it remains to show only that all such strings are generated. Let x have an equal number of a’s and b’s. If x=ε then clearly x is generated. Assume all x with equal number of a’s and b’s and |x|<n are generated. Let x be of length n.
Background image of page 1

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

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

This note was uploaded on 05/19/2008 for the course COM S 381 taught by Professor Hopcroft during the Fall '05 term at Cornell University (Engineering School).

Page1 / 2

cs381-fall02-prelim2-solutions - CS381 Fall 2002 Second Mid...

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

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