1
$\begingroup$

There is a saying by Computer Science Professor's everywhere :

PDA Checks the intelligence of Students, as certainly there is no approach except power and imagination
of mind to solve problems and design PDA...

While thinking today i thought How can we design automata of a^2n b^(2n-1)

I tried my best : For example let q0 is initial state and top of the empty stack has Z.

So, Let say Transition of (q0, a , Z) = (q1,Z)

            Transition of (q1, a , a) = (q1,a)

            Transition of (q1, b , a) = (q2,-)

            Transition of (q2, $ , Z) = (qf,Z)

I was able to solve this problem all of a sudden...

My doubt is still the same, How to be the best in solving PDA problems and Is there any way to define a strategy to solve problems ?

P.S. Your comments are welcome if i did something wrong in above stated question

$\endgroup$
2
  • 1
    $\begingroup$ The golden rule of problem solving is: practice! $\endgroup$ Commented Oct 21, 2013 at 17:51
  • $\begingroup$ @YuvalFilmus : yep that's true for everything in life.... Thnks... $\endgroup$
    – Shubham
    Commented Oct 21, 2013 at 22:55

1 Answer 1

2
$\begingroup$

One technique is to start out with a context-free grammar, and apply an algorithm to get a corresponding PDA. Often, writing a grammar might be a bit easier than writing the PDA directly. In this case, it seems (to me) to be fairly easy to arrive at the grammar $S \rightarrow aaSbb \mid aab$, from which a PDA follows by construction (see this, for example, for some info on how to do such a conversion, if this is new to you)

If you want to build the PDA directly, another way to think about it is to start from the end of strings, and ask yourself what needs to be on the stack to make it easy to tell you need to accept the string. In your case, if you're looking at the last part of the string - say, you've started seeing $b$'s, what would it be really helpful to have on the stack? Well, the easiest thing would be to have $2n-1$ symbols on the stack. If we can arrange that, then when we get to $b$'s we can simply pop one symbol off the stack for every $b$ we read, and accept if the stack is empty when we're done with the input. How can we leave $2n-1$ symbols on the stack after reading $2n$ of the $a$ symbol? Well, we could put a symbol on the stack each time we read an $a$, and then, before we start reading $b$'s, remove one symbol from the stack. We get three phases to the computation: (1) read an even number of $a$'s and push a symbol onto the stack for each $a$ you read; (2) remove one symbol from the stack; (3) read $b$'s until the stack is empty and/or you run out of input. We'd get a PDA like this:

q    s    e    q'    s'
--   --   --   --    --
q0   Z    a    q1    aZ
q0   a    a    q1    aa
q0   a    -    q2    -
q1   a    a    q0    aa
q2   a    b    q2    -
q2   Z    -    q3    Z

We have start state q0 and accepting state q3. Entries of - in the e column indicate $\lambda$-transitions, whereas entries of - in s' indicate popping a symbol off the stack.

$\endgroup$
3
  • $\begingroup$ The PDA solution you described is somehwat skeptical and not complete.... Check for aaaabbb.. $\endgroup$
    – Shubham
    Commented Oct 21, 2013 at 22:35
  • $\begingroup$ @Shubham Good catch, I was missing a rule (now added). $\endgroup$
    – Patrick87
    Commented Oct 21, 2013 at 22:39
  • $\begingroup$ Your method is appreciable... Respect $\endgroup$
    – Shubham
    Commented Oct 22, 2013 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.