For starters this is a homework question. I have an idea but I am still not able to get the correct answer. I’m not asking for the answer I am just asking for help to answer the question.
I am currently trying to write a context free grammar for the language
a(iterated i times)db(iterated j times), for i and j>=0, and j = 2 * i.
So basically there are twice as many a’s as b’s and a d in between the 2. For example:
d, adbb, aadbbbb, ……
Here is about what I have, I don’t have much… I understand the concept of these CFG’s I am just not sure about the logic for this question. I am not sure If i am even going the right direction…
S -> AdB
A -> EMPTY
A -> aAB
B -> DD
Thanks.
I guess I’ll start off hints by saying that you only need 2 statements to solve this. I’d rather see some of your work (even in the wrong direction!) if I’m to give you any more, though.
EDIT
Thanks for posting what you’ve got. Here’s a couple thought exercises that will hopefully get you moving in the right direction:
Wikipedia’s article on CFG’s has some help on this if you’re still stuck.
When you get that last one, you’ll see the trivial addition to get to your grammar.