PDA to accept a language of strings containing more a's than b's

后端 未结 5 761
一生所求
一生所求 2021-02-11 01:30

Produce a PDA to recognise the following language : the language of strings containing more a\'s than b\'s

I have been struggling with this

5条回答
  •  名媛妹妹
    2021-02-11 01:52

    I'm assuming you mean strings of the form a^nb^m, where n>m.

    The idea is relatively easy, for a you push it on the stack (in a loop), for b you switch to a separate loop to pop a from the stack. If the stack is ever empty, you give up with a FAIL. If in the first loop you get anything other than a or b, or in the second loop you get anything other than b, you give up with FAIL.

    At the end you try to pop another a and if the stack is empty you give up with a FAIL (ie, you had at least as many b's as a's on the stack, possibly more). If not, SUCCESS.

    Edit: As a side note, I'm not convinced this is the right site for this question, might be better on programmers. Not sure though so not voting to close.

提交回复
热议问题