4

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?

Raphael
  • 73,212
  • 30
  • 182
  • 400
m0meni
  • 143
  • 5

1 Answers1

3

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

  1. $L(G)$ is the language of all palindromes over $\{0,1\}$.
  2. $L(G) = \{ x \in \{0,1\}^* : x \text{ is a palindrome} \}$.
  3. $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.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514