How to read this PDA?

206 Views Asked by At

PDA

This is an old HW question where I had to find out how many times the q\loop state was visited for each given string:

bb: 5

abab: 0

abba: 8

babbab: 11

I understand how the 1st string visits the state 5 times and the 2nd string is not accepted, but I don't know the process for the 3rd and 4th strings. I would really appreciate it if someone could just walk through the states visited for the 3rd or 4th string because I keep getting stuck

1

There are 1 best solutions below

0
Welbog On

This PDA matches palindromes. How does it do it? It looks for P on the stack and replaces it with either aPa or bPb, then matches a on the stack with a in the input. Likewise for b. It replaces P nondeterminstically.

Let's walk through #3. We'll focus on Q_loop, which I'll just call L for simplicity. The top of the stack will be the rightmost character.

  1. The first time we get to L, the input is abba and the stack is $P. We will nondeterministically follow the e,P->a transition.
  2. The input is abba, the stack is $aPa. We will follow the a,a->e transition.
  3. Input: bba, stack: $aP. Follow e,P->b.
  4. Input: bba, stack: $abPb. Follow b,b->e.
  5. Input: ba, stack: $abP. Follow e,P->e.
  6. Input: ba, stack: $ab. Follow b,b->e.
  7. Input: a, stack: $a. Follow a,a->e.
  8. Input: e, stack, $. Follow e,$->e and accept in the next state.