Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:42:59+00:00 2026-05-20T09:42:59+00:00

I’m working on some test preparation material and stuck on this problem. Show a

  • 0

I’m working on some test preparation material and stuck on this problem.

Show a context free grammar for L = {w e {a,b}*: w = wR and every a is immediately followed by a b}.

wR is w in reverse. So, in english, a palindrome with every “a” being followed by a “b”, using any number of a’s and b’s.

So far, I got this for the reverse portion, but I can’t figure out how to incorporate the every a is followed by a b part while ensuring the palindrome property will still hold.

S -> bSb | b | [the empty string]

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:43:00+00:00Added an answer on May 20, 2026 at 9:43 am

    Since every “a” must be followed by a “b”, and the resulting word must be palindrome (it is the same if being read from the end to the beginning), this implies that every “a” must also be preceeded by a “b”.

    We start building the word from the middle, growing in both directions. The rule is that when the middle section ends (and therefore begins) with an “a” (this is the nonterminal A), then it must be followed (and preceeded) by a “b”. On the other end, when the middle section is sorrounded by “b”s (this is nonterminal B), it can expand with a single “a” (the previous case), or any number of “b”s. The special case of evenly numbered “b”s in the middle are also handled. The start symbol S only allows words limited by “b”s, therefore all rules are matched.

    S -> B | [empty]
    B -> bAb | bBb | bb | b
    A -> aBa | a
    

    Edit: My previous solution was incorrect, I hope this works now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.