0% found this document useful (0 votes)
17 views

Second midterm solutions

Automata

Uploaded by

Bijay Nag
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Second midterm solutions

Automata

Uploaded by

Bijay Nag
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CS381 Second Mid Term Solutions Friday Nov 7, 2003

Fall 2003 Olin 255 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. Give a context-free grammar for the set {a i b j | i ≤ j ≤ 2i} .


Solution: S → aSb | aSbb | ε

2. Prove or disprove that L = {a n b m c n d m | n ≥ 1, m ≥ 1} is a context-free language.


Solution: Not context free by pumping lemma. Assume L is a cfl. Let k be integer of
pumping lemma. Select z = a k b k c k d k . Suppose z is written uvwxy where | vwx |≤ n and
vx ≠ ε . Note vwx cannot contain both a’s and c’s nor can it contain both b’s and d’s.
Thus, uv 2 wx 2 y will either have a different number of a’s and c’s or a different number of
b’s and d’s and will not be of the form a n b m c n d m . Hence uv 2 wx 2 y is not in L, a
contradiction. Therefore L is not a cfl.

3. Describe in English how to convert a many state pushdown automaton to a one state
pushdown automaton.
Solution: The pushdown store alphabet of the one state machine will be Q × Γ × Q where
Q is the set of states of the multi-state machine and Γ is its pushdown store alphabet.
The one state pda will store the current state of the multi-state pda in the first component
of the top stack symbol. When the pda grows its store by writing a new symbol on the
store it places the state in the first component of the top symbol and guesses the state it
will be in when it erases the top symbol exposing the symbol just below. The guess is
stored in the symbol just below the top. To verify that the guess is correct it will also
store the guess as the third component of the symbol on the top of the store. Whenever a
symbol is erased from the store a check is made that the third component is the new state
since that is the state that is in the first component of the symbol below which will
become the new top symbol.

4. Let L1 be a context-free language. Suppose L2 is obtained from L1 by adding and


deleting a finite number of strings. Is L2 a context-free language? Justify your answer.
Solution: Let F1 be the finite set of strings added to L1 and F2 the finite set of strings
removed. F1 and Σ* − F2 are regular sets. Since the class of cfl’s is closed under union
and intersection with regular sets
L2 = ( L1 U F1 ) I ( Σ* − F2 )
is a cfl.

You might also like