Homework 4 solutions 1. L = {anbmck | n+k=m} Accept on empty

Homework 4 solutions
1. L = {an bm ck | n + k = m}
Accept on empty stack
Comment: This pda pops ‘a’ for each ‘b’. Once all the a’s are popped off (i.e. ⊥
is exposed as top of stack), the b’s are pushed in. Then, a ‘b’ is popped for each ‘c’ in the input,
with acceptance on the empty stack. Transition from q0 to q2 accounts for case n=0 (and m = k).
Likewise, transition from q1 to q4 coressponds to the case where k=0 (n = m).
2. L = {a2n bn | n ≥ 1}
Accept on empty stack
Comment: 2 a’s are popped for each b in the input with the use of states q1 and q2 .
3. L = {w | number of a’s in w = number of b’s in w}
1
Accept on empty stack
Comment: At any point, this pda will have either only a’s on the stack (other than
⊥) or only b’s. The numbers of a’s (or b’s) will be equal to how many more a’s
than b’s (resp. how many more b’s than a’s) were seen in the input thus far.
4. L = {an bm | n 6= m}
Accepts by final state
The top part involving q1 , q2 , and q3 corresponds to the case where n > m. After
popping ‘m’ a’s in state q2 , there should still be a’s on the stack (since n > m).
The transition from q1 to q3 corresponds to the case where m=0. Note since n > m,
now we have n ≥ 1.
The bottom part involving q4 , q5 , and q6 corresponds to the case where m > n.
2
n 6= m can be thought of as (n > m) or (m > n). This disjunction is captured
in the pda using non-determinism (choice to move to q1 or q4 from
q0 ).
5. L = {w1 can bn w2 | w1 , w2 ∈ {a, b}∗ , length(w1 )=length(w2 )}
Accept by empty stack
In q0 , 0’s are pushed to keep track of the length of ‘w1 ’. At end of w1 , a
‘c’ is encountered and pushed onto stack. When when w1 = , the stack has
just ⊥. In q1 , the a’s (of an bn part) are pushed. These a’s are
popped for each b in the input of q2 . When equal number of a’s and b’s have been
seen, a ‘c’ will be at the top of the stack. Now pda transitions to q3 to check if
length of w2 is same as length of w1 .
6. L = {an bm ck | n = m or m = k}
3
Accept by empty stack
Non-determinism is used to account for the two cases. The ‘top’ part with q1 ,
q2 , and q3 checks for the case where n = m (equal number of a’s and b’s), and the
‘bottom’ part with q4 , q5 , and q6 checks for the case where m = k (equal number of b’s and c’s).
Note that the cases where n, m, and/or k equals 0 are accounted for with -transitions on the empty stack.
4