-2

How to create a context free grammar for L={w∈{a,b,c}*|w has more as than bs}

jam
  • 3,640
  • 5
  • 34
  • 50
  • This question doesn't belong here. Post such questions on http://cstheory.stackexchange.com/ – Ravindra S Jul 15 '12 at 11:11
  • Both homework and context-free-grammar are valid tags. – hythlodayr Jul 15 '12 at 11:31
  • @hythlodayr Valid tags doesn't make such questions valid to be posted on SO. – Ravindra S Jul 15 '12 at 16:20
  • I'm not sure I follow. As per the homework tag: "Homework means the question is requesting help with school homework. This lets potential answerers know that they SHOULD guide the student in solving the problem, and SHOULD NOT simply show the complete answer." Also, http://stackoverflow.com/faq gives good guidance on what's out-of-scope. Since most programmers are at least familiar with undergraduate CS theory (hence the CFG tag), the question seems right at home on stackoverflow. What am I missing? – hythlodayr Jul 16 '12 at 01:37

1 Answers1

0

First, you can convince yourself it's possible by thinking of it in pushdown automata form. Informally: When reading the tape, push any "a"s into the stack but pop stock the stack when reading "b". When the tape-read is finished, accept if the stack has an "a". Reject if otherwise.

CFG: Basically, you need to bound your grammar so that whenever a "b" is created there is at least one "a" also in the mix.

Hints:

  1. Ignore "c" for a bit
  2. Write down the ways a valid language can begin and end (basically two character combinations) and try generalizing from there.
hythlodayr
  • 2,377
  • 15
  • 23