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
  • 1
    We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – Nathaniel Dec 16 '21 at 16:34
  • https://cs.stackexchange.com/q/11315/755 – D.W. Dec 17 '21 at 04:26

0 Answers0