This question is upcoming for my midterm and I can't figure it out. My professor broke it down in two statements (n>m) and(m>n) and left us at that.
Find a context free grammar for $L = \{ a^n b^m : n \neq m \}$
This question is upcoming for my midterm and I can't figure it out. My professor broke it down in two statements (n>m) and(m>n) and left us at that.
Find a context free grammar for $L = \{ a^n b^m : n \neq m \}$
On
Hint:
I hope this helps $\ddot\smile$
On
yes,the idea to form grammars for this falls in two divisions 1)nm
so lets define the grammar for each individually and combine.
S -> X | Y
X -> aXb | Xb | b
Y -> aYb | aY |a
On
In this problem, strings start with a number of a's followed by the number of b's. there may be two cases
On
As per the given problem we have two cases i.e.
The minimum string that need to be generated is either a or b.
Then this production rule must satisfy all the conditions:
S -> Sa | Sb | E | a | b
You have two cases like your professor stated: $n > m$ and $n < m$. Let $x \to c_1$ and $x \to c_2$ be two rules that initiate the two cases, i.e. $x$ is the start variable. Then for example, for $n > m$ this is handled by $c_1$ and the context free grammar rules to generate it are $c_1 \to a$, $c_1 \to a c_1 b$, and $c_1 \to a c_1$. Similarly for $c_2$ to handle the case $n < m$.