0

Let the alphabet be $Σ = \{0, 1\}$. For any string $w ∈ Σ^*$ of length at least 2, define the operation $C_2(w)$ to be a cyclic shift of size 2 on $w$. That is, if $w = w_1w_2 \cdots w_n$ with $n ≥ 2$ and each $w_i ∈ Σ$, then $C_2(w) = w_3 \cdots w_nw_1w_2$ if n ≥ 3, and $C_2(w) = w$ if $n = 2$. Recall that $w^R$ means $w$ written backwards.

Give a context-free grammar that generates the following language: $$ \{w \mid w \text{ has length at least 2 and } C_2(w) = w^R\}. $$

I'm having trouble constructing the context free grammar, so any tips would be much appreciated!

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
marcelomo
  • 29
  • 4

1 Answers1

2

Let us see which words satisfy $C_2(w) = w^R$. Write $w = \sigma \tau x$, where $\sigma,\tau \in \Sigma$ and $x \in \Sigma^*$. Then $C_2(w) = x \sigma \tau$ and $w^R = x^R \tau \sigma$, and so $C_2(w) = w^R$ iff $x = x^R$ and $\sigma = \tau$.

You should be able to use this information in order to construct a grammar for your language.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503