2

Consider the language $$ \{ w \in \{0,1\}^* : \#_0(w) \ge \#_1(w) \} $$ consisting of all words over $\{0,1\}$ in which the number of zeroes is at least twice the number of ones.

Is this regular, context-free, Turing decidable?

My Idea

It's not regular, because we need to track the number of zeros and so it cannot be done with a finite number of states. I am not sure if this argument is a formal one.

Turing Decidable - Yes

Take a machine which reads 1 from the end, writes an X there and then traverses the tape and X's two 0's.

If after all ones are gone the tape is empty of there are still zeroes left then it's accepted. Otherwise, if there are ones left on tape after this operation, it's rejected.

Context-Free

I am unable to find any context free grammar for it. Neither can I prove that it's not context-free.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
pensee
  • 131
  • 3

2 Answers2

1

The language is context-free. As you read the string, you'll need a counter comparing two values: $\#_0 \cdot 2$ and $\#_1$. Such counter can be implemented using the stack of the PDA.

When a $0$ is read:

  • if there is a $1$ on top of the stack, pop it. If the stack is now empty, add a $0$, otherwise pop again.
  • else add $0$ to the stack twice

When a $1$ is read:

  • if there's a $0$ on top of the stack, pop it.
  • else add $1$ to the stack

It is easy to see* that the stack contains now the difference between $\#_0 \cdot 2$ and $\#_1$, encoded as the number of symbols on stack and the symbol used. After the entire string has been scanned, the top symbol of the stack tells which of the numbers is greater: if the top symbol is $0$ or the empty stack symbol, accept. Otherwise reject.

*If you need a more formal proof of this construction's correctness, it is fairly easy proven by induction: first establish that the symbols of the stack represent the correct counts after reading the first symbol, then perform an induction step with the assumption that the first $n$ symbols resulted a correct count on the stack and showing that the $n+1$th symbol read doesn't violate this correctness.

kviiri
  • 1,248
  • 6
  • 12
0

Let $L$ be your language

$L$ is context free since the following CFG generate all possible strings in $L$

S -> 1KK | KK1 | K1K | K | Ɛ
K -> S0S 

$L$ is decidable since $L$ is context free and all context languages are also decidable

$L$ isn't regular since it doesn't respect the Pumping Lemma:

For a lenght $k$ we can chose the word $w = 0^{2k} 1^k \in L$

Then if we divide $w$ in $xyz$ where:

$|y| > 0$

$|xy| < k$

$y$ must be only made of zeroes, it we chose the exponent $i=0$ we get $xy^0z$ that isn't in $L$, thus $L$ isn't regular.

Alecs
  • 1
  • 2