2
$\begingroup$

I'm having trouble to find context free grammars which generate following languages:

  1. $L_1 = \{a^nb^{2n}∣n\ge1\}$

  2. $L_2 = \{a^pb^{p+q}a^q∣p,q\ge1\}$

  • 0
    Welcome to Math.SE! Questions which elaborate on what the asker is having difficult with or confused about are the most likely to receive helpful answers.2017-01-10

1 Answers 1

1

HINT: For $L_1$ you need a very small modification of a context-free grammar for $\{a^nb^n:n\ge 1\}$, and I suspect that you’ve seen such a grammar: it has just two productions, $S\to aSb$ and $S\to ab$. That same grammar contains the essential idea needed for a grammar for $L_2$ as well. Start with a production $S\to XY$, let $X$ produce strings of the form $a^pb^p$, and let $Y$ do the rest.

  • 0
    So for L1 is it just two productions with S → aSbb and S → abb?2017-01-10
  • 0
    @Tes: That’s right.2017-01-10
  • 0
    And for L2 would this be correct: S → XY, X → aXb, X → ab, Y → bYa, Y → ba?2017-01-10
  • 0
    @Tes: Yes, exactly.2017-01-10
  • 0
    wow i understand it now, thank you so much!2017-01-10
  • 0
    @Tes: You’re welcome!2017-01-10