HW 5 Solutions
HW 5 Solutions
HW 5 Solutions
1. Design a PDA to accept the strings in (0+1)* such that no prefix has more 1’s than 0’s.
01001011001 is a string in this language. Say whether your PDA accepts by final state or empty
stack.
1,0|
0,0|00
0,Z0|0Z0 Accepts by final state.
,X|Z0X ,Z0|
S T
,0|
2. Design a PDA to accept {aibjck | i=j or j=k}. Say whether this accepts by final state or empty stack.
a,X|X b,a| c,Z |Z 0 0
,Z0|Z,X|X
0 ,Z0|Z0
,Z0|Z0
UX V
TX ,Z0|
,X|Z0X
S
a,Z0|Z0 b,X|X c,b| W
,Z0|Z0 ,Z0|Z0
,X|X ,X|X ,Z0|
X YX ZX
S
4. Convert the following grammar into a PDA that accepts by empty stack.
S => 0S1 | A
A => 1A0 | S |
1,1|
0,0|
,S|0S1
,S|A
,A|1A0
,A|S
,A|
,X|SX
Q
5. Here is a PDA that accepts strings in (0+1)* with the same number of 0’s and 1’s. This PDA
accepts by empty stack. Chomsky’s algorithm gives a grammar equivalent to this PDA, with
grammar symbols of the form [pXq]. Give a derivation in this grammar for the string 0101.
1,1|11
1,0|
1,Z0|1Z0 Derivation:
0,0|00 Start => [PZ0Q]
0,1| => 0[P0P][PZ0Q]
0,Z0|0Z0 => 01[PZ0Q]
=> 010[P0P][PZ0Q]
=> 0101[PZ0Q]
=> 0101
,Z0|
P Q