Question #38638

{w| w has equal number of a’s and b’s } is
A. regular
B. context-free but regular
C. context-sensitive but not context-free
D.type-0 but not context-sensitive

Expert's answer

Answer on Question#38638 – Math - Other

For a string ww in L={wwL = \{w \mid w has equal number of a's and b's }\}, let jj and kk be the number of asa's and bsb's in ww respectively. Then observe that LL consists of strings in which j=kj = k, so LL consists of strings in which jkj \neq k, but that any two of these suffice by transitivity, so in particular we take jkj \neq k.

We can create a PDAPDA (pushdown automaton) and this PDAPDA accepts any string over the alphabet Σ={a,b}\Sigma = \{a, b\} in which the number of asa's does not equal the number of bsb's by only accepting if j>kj > k or k>jk > j. Notice that j>kj > k or k>jk > j if and only if jkj \neq k.

CFLs (context-free languages) are closed under union, so the union of the two languages recognized by these PDAs are context free. We've already argued that the union of these two languages is LL, so we conclude that LL is context free.

Answer: B.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS