3

My professor gave us an old exam to look over for our final exam and I am having a hard time understanding the push down automata problem he gave. In the problem it says:

Let $\Sigma = \{0,1\}$ and $B$ is the collection of all strings that contain at least one $1$ in the second half. To state it more precisely: $B=\{uv\mid u \in \Sigma^{\ast}, v \in \Sigma^{\ast} 1 \Sigma^{\ast}, |u|\geq|v|\}$. Give a PDA that recognizes $B$. Give a diagram to describe your PDA.

My question is why do I need a PDA or really a stack for this because all I am looking at is the second half which I can just epsilon to the second half and then when I read a $1$, go to the accept state. For example if $u=1001010101$ and $v=000011$, wouldnt I just loop around for a bit for u and then epsilon over to say I am now looking at $v$. Then when I read the first $1$, I just accept. I wouldnt need to use the stack at all would I? I'm not sure if I understand it correctly or not and would appreciate any help.

Raphael
  • 73,212
  • 30
  • 182
  • 400
user1715916
  • 133
  • 1
  • 3

3 Answers3

3

The problem with your approach is that you are not checking that $|u| \geq |v|$ - for example the string $0100$ would be accepted. Remember that the 'magic' of non-determinism is that if there is a way to reach an accept state, it will find it, it makes no guarantee that it accepts only the things you want it to.

So in this case, you still need to check that the size of the two parts are suitable, for which we need1 a stack.

As a side note, $B$ can also be expressed as $\{u1v\mid u \in \Sigma^{\ast}, v \in \{0\}^{\ast}, |u| \geq |v|\}$, not that this really changes much, but it's a little simpler (in terms of the PDA).

Footnotes:

  1. As Babou points out in his answer, you don't need a stack as such, a simple counter suffices, but you do need something beyond what a DFA/NFA can manage.
Luke Mathieson
  • 18,373
  • 4
  • 60
  • 87
1

You do not need a stack to do this, but you do need a counter. A counter automaton is a PDA with only a single stack symbol (there may be a second one used only to mark the bottom of the stack, and thus test emptyness). It is a strictly weaker type of automaton.

This is needed to identify the first half of your string that you want to epsilon away.

Then, non-determinism is your friend. You read the first half of the string, and epsilon it away, as you say. But you are careful to count the length of the first half in your counter/pushdown.

They you read the second half checking it contains a 1, but also decrementing the counter to check that the "second half" has the same length as the first. If both conditions are met, you accept, else you reject.

Non-determinism is used only to decide when you have reached the middle of the string. If you do the wrong choice, your computation fails. But if the string is in the language and you do the right choice, then the compuation succeeds ... which is all you want.

babou
  • 19,645
  • 43
  • 77
0

Here's a sketch of a PDA which does the job:

In state $q_0$, push the symbol | (a tally marker) onto the stack and consume one input symbol, or do an epsilon transition to $q_1$.

In state $q_1$, on input $1$, pop a tally marker and transition to $q_2$. On input $0$, pop a tally marker and stay in $q_1$.

In state $q_2$, accept. For example, on any input symbol, pop a tally marker. Maybe also pop a tally marker on epsilon.

The exact behavior in $q_2$ depends on what counts as an accepting configuration in the particular definition of DFA you're working with.

I believe this deals with all even-length strings. By the precise definition given, the second half excludes the middle character in odd-length strings. To account for this, add a transition from $q_0$ to $q_1$ which consumes an input symbol without changing the stack.

Why do you need a stack? As others have pointed out, other bookkeeping structures such as a counter would suffice; in fact, I'm using the stack as a counter.

A more limited but still instructive question is then: where do I rely on the stack in my specific solution? How and why would it break if the stack was removed? (In other words: instead of asking "why does every solution need a stack?" we can ask "why does this one solution need a stack?".)

The main idea of my construction is similar to yours (OP's): twiddle my thumbs while waiting for a $1$, then go to an accepting state. Of course, a $1$ in the first half of the string (or at the middle position) shouldn't cause the PDA to accept. I use the stack-as-a-counter to know (in a non-deterministic sense) whether the input symbol being consumed is in the second half of the string or not.

Without the stack-as-counter, well, I don't know what my construction would be, but if it was coherent it probably would accept $10$ even though it shouldn't.

Jonas Kölker
  • 729
  • 3
  • 11