HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Finding the language of a context-free grammar?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thefreelanguagegrammarfindingcontext

Problem

Given following question:

Let $G$ be a context-free grammar, $G=(V, \Sigma, R, S)$, that has start
variable $S$, set of variables $V = \{S\}$, set of terminals $\Sigma = \{0, 1\}$, and set of rules $R = \{S \rightarrow \epsilon , S \rightarrow 0 , S \rightarrow 1 , S → 0S0 , S \rightarrow 1S1\}$. Describe $L(G)$,
the language of the grammar $G$.

I know that $\epsilon, 0, 1, 00, 11, 010, 101, 01010, 10101, 10001, 01110$ all fit the grammar, but I can't find a formal way to express what I want to say. Perhaps I don't know the symbols or something, but I would express it as

$L(G) = \{(0\ or\ 1)^n(0\ or\ 1)^{(0\ or\ 1)}(0\ or\ 1)^n,\ n \ge 0\}$

Is this right? Is there a more formal way to express this?

Solution

Your grammar generates the language of all palindromes. It can be described in the following ways:

  • $L(G)$ is the language of all palindromes over $\{0,1\}$.



  • $L(G) = \{ x \in \{0,1\}^* : x \text{ is a palindrome} \}$.



  • $L(G) = \{ x \in \{0,1\}^* : x^R = x \}$.



The first option is really the best, but unfortunately your TAs are expecting the third option.

Context

StackExchange Computer Science Q#65738, answer score: 3

Revisions (0)

No revisions yet.