Machine-translated by Google. Questions are authored in English.
Top

Discussion

The following CFG S → aB | bA, A → a | as | bAA, B → b | bs | aBB generates strings of terminals that have

  • A.odd number of a's and odd number of b's
  • B.even number of a's and even number of b's
  • C.equal number of a's and b's
  • D.not equal number of a's and b's

Answer: C

The grammar generates strings with equal numbers of a's and b's. A generates the strings that have one more a than b's, B generates those with one more b than a's, and S starts with a followed by a string with one more b, or b followed by a string with one more a, so the totals are always equal. A check: S gives aB which gives ab, and bA gives ba, each with one a and one b. So the strings have an equal number of a's and b's, option (C). The options on odd, even and unequal counts are therefore wrong.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.