0

Where bin(n) is the shortest binary representation of n. First, we can see that we can rewrite it as $bin(n)bin(2(n+1)+1)^R$ which implies that the second word will always start from 1. We can also see that the words in that language will be of form:

  • $w011w^R$ if the word ends with 0, because we need to just get to bin(n+1) and it switches one zero
  • $w01^n10^n1w^R$ if the word ends with 1, but there is zero before it at some point in the word, then after switching all 1's to 0's we need to add one more 1
  • the last case is when we have all 1's then the word becomes $1^n10^n1$

From this we can try to construct a CFG and here is my question, is that grammar correct?


S  -> N | 1Q1
N -> 1N1 | 0N0 | T
T  -> 011 | 0P1
P  -> 1P0 | 1
Q  -> 1Q0 | 1

where Q is supposed to take care of the case all 1's

Travis
  • 1

0 Answers0