Pushdown Automata Construction - grammar

How to construct a PDA accepting the language :
( {a^ib^kba^i | i>=0,k>0})

To get a PDA for this language, I'd recommend writing two PDAs for each of languages in the union separately, then nondeterministically jumping to one or the other PDA.
To get a PDA for a^(2n) | n > 0, we just need to make sure the number of a's is even; this is a regular language so a DFA will suffice (a DFA is just a PDA that doesn't do anything interesting with the stack)
/---a---\ state stack input state' stack'
| | q0 Z a q1 Z
V | q1 Z a q0 Z
----->q0--a-->q1
To get a PDA for the other one we see that the numbers of a's on the front and back must match; we need the stack for this. We can make the PDA push a's it reads until it sees the first c; then we can make it read c, then at least one d, then another c, and finally the same number of a's as we pushed earlier:
state stack input state' stack' comment
q0 x a q0 ax push a's until we see a c
q0 x c q1 x read the required c
q1 x d q2 x read the required d
q2 x d q2 x read as many d as needed
q2 x c q3 x read the 2nd required c
q3 ax a q3 x pop a's until we run out of input
q3 Z q4 Z Z accept on empty stack+state
To hook these up you just need to rename the states of the first one to q0' and q1' and then add a new start state q0'' that works like this:
state stack input state' stack' comment
q0'' Z - q0 Z guess we're going to the 2nd PDA
q0'' Z - q0' Z guess we're going to the 1st PDA
As far as your second question goes:
suppose we have a PDA that accepts by final state but not necessarily empty stack; that is, if the PDA runs out of input while in the final state(s), it accepts, otherwise it rejects. We can add a new state, make it the only accepting one, and add empty transitions from all previously accepting states to it. This new state can have empty transitions to itself that only serve to clear the stack without consuming any additional input. This construction shows that if we can accept by final state alone, we can accept by final state and empty stack together.
suppose we have a PDA that accepts by empty stack but not necessarily final state; that is, if the PDA runs out of input at the same time the stack is empty, the PDA accepts. Add a new state and have all states in the PDA transition to it on the empty stack. Make this state accepting and give it no transitions. The PDA will crash unless the input was already exhausted and it can only be reached if the stack was also empty. This construction shows that if we can accept by empty stack alone, we can accept by empty stack and accepting state together.

Related

How to show that if the language L is regular, then L' is regular?

Let L be any regular language and a ∈ Σ. How to show that the language L'={uav | uv ∈ L} is regular too?
Wikipedia says a way to proove it is to lead it back to a regular language but I don't understand how to do that in this case. Hope somebody can help.
There are lots of ways to show this. I think an argument whereby we construct a DFA is particularly easy to visualize.
Imagine a DFA for your language L. Let's call it M. Imagine it sprawled out in diagram form on a table. Now, imagine making a copy of M and spreading it out next to M on the table. Call it M'.
Now - from M, add a new transition from state q of M to the corresponding state q' of M'. The transition is on the symbol a.
Now, consider the aggregate machine whose start state is the start state of M and whose accepting states are the accepting states of M'. This machine starts out accepting strings in L, then accepts an a somewhere in the middle, and then continues accepting strings in L from where it left off. This is the language we were going for and we have defined a perfectly reasonable NFA for it. Since any language accepted by an NFA is regular, our language is regular.

Finding a grammar for this language

I need to find a context free grammar for the following language:
L= { w from { a,b,c,d }* : #a+2#b=2#c+#d }
Here is my attempt, but I doubt it is correct:
S -> aSd|dSa|BSC|CSB|abSdc|baScd|dcSab|cdSba|SS|λ
B -> c|dd
C -> b|aa
You can construct a PDA that recognizes the language like this:
The characters a and b in the input correspond to a on the stack.
The characters c and d correspond to c on the stack.
If the stack is empty or the top is a, and a is on the input, consume it and push a to the stack.
If the stack is empty or the top is a, and b is on the input, consume it and push aa to the stack.
If the stack is empty or the top is c, and c is on the input, consume it and push cc to the stack.
If the stack is empty or the top is c, and d is on the input, consume it and push c to the stack.
If the stack top is c and a is on the input, consume a and pop the c.
If the stack top is c and b is on the input, consume b and pop the c, moving to a special state that either pop another c or pushes an a if the stack is empty.
...
The accept state is where both the input and stack are empty.
That means you must be able to construct a CFG. I think you're on the right track, but this CFG is going to be a pain to write since there are no ordering constraints. This means you'll have a lot of permutations of the same basic rule.

Can final and non-final states having identical configurations be merged together in a minimal DFA?

I have been practicing some questions on automata theory where I came across a question on minimal dfa at which I can't figure out where I have gone wrong.I am getting 4 states in the minimal dfa but my book says answer is 3.The question asks a given NFA to convert into a minimal DFA and count the number of states in the latter one.The given NFA(p and r are initial and final states respectively) is:
{p}---b-->{q}
{q}---a--->{r}
{q}---b--->{s}
{r}---a--->{r}
{r}---b--->{s}
{s}---a--->{r}
{s}---b--->{s}
I am getting 4 states:[r],[p],[q,s],[dead].Can the final [r] and the non-final state [q,s] be merged here since they lead to the similar configuration on receiving inputs a and b??I have learned that final and non-final states cannot be in the same equivalence class...
OK, let's start with all possible states for our DFA, there will be 17 (2^4 for the 4 symbols plus 1 for the empty set). These will be:
{}
{p}
{q}
{r}
{s}
{p,q}
{p,r}
{p,s}
{q,r}
{q,s}
{r,q}
{r,s}
{p,q,r}
{p,q,s}
{p,r,s}
{q,r,s}
{p,q,r,s}
Now that we have all the possible sets, let's highlight all that are reachable from the start state p:
{}
{p} --- Start state. From here we can get to {q} only as defined by the transition {p}--b-->{q}
{q} --- from here, we get to r or s, so {r,s} as defined by {q}--a-->{r} and {q}--b-->{s}
{r}
{s}
{p,q}
{p,r}
{p,s}
{q,r}
{q,s}
{r,q}
{r,s} --- from here, we can only get to r or s (the same state!), so we're at a dead end.
{p,q,r}
{p,q,s}
{p,r,s}
{q,r,s}
{p,q,r,s}
The three accessible states are thus {p},{q}, and {r,s}. The reason the "dead" state, or empty set is not reachable is that none of the accessible transitions lead to it.
Hope this helps!

How to solve δ(A,01) for this DFA?

Consider the DFA :
What will be δ(A,01) equal to ?
options:
A) {D}
B) {C,D}
C) {B,C,D}
D) {A,B,C,D}
The correct answer is option B) but I don't get how. Please some one explain me the steps to solve it and also in general how do we solve sit for any DFA and any transition?
Thanks.
B) Option is not Correct answer! for this transition graph.
In Transition Graph(TG) symbol ε means NULL-move (ε-move). There is two NULL-moves in TG.
One: (A) --- `ε` ---->(B)
Second: (A) --- `ε` ---->(C)
A ε-move means without consume any symbol you can change state. In your diagram from A to B, or A to C.
What will be δ(A,01) equal to ?
Question asked "what is path from state A if input is 01". (as I understand because there is only one final state)
01 can be processed in either of two ways.
(A) -- ε --->(B) -- 0 --> (B) -- 1 --> (D)
(A) -- ε --->(C) -- 0 --> (B) -- 1 --> (D)
Also, there is no other way to process string 01 even if you don't wants to reach final state.
[ANSWER]
So there is misprinting in question (or either you did).
You can learn how to remove NULL-move from transition graph. Also HOW TO WRITE REGULAR EXPRESSION FOR A DFA
If you remove null-moves from TG you will get three ways to accept 01.
EQUIVALENT TRANSITION GRAPH WITHOUT NULL-MOVE
Note there is three start-states in Graph.
Three ways:
{ABD}
{CBD}
{BBD}
In all option state-(B) has to be come.
Also, you have written Consider the DFA : is wrong. The TG is not deterministic because there is there is non-deterministic move δ(A,ε) and next states are either B or C.

What is the language of this deterministic finite automata?

Given:
I have no idea what the accepted language is.
From looking at it you can get several end results:
1.) bb
2.) ab(a,b)
3.) bbab(a, b)
4.) bbaaa
How to write regular expression for a DFA
In any automata, the purpose of state is like memory element. A state stores some information in automate like ON-OFF fan switch.
A Deterministic-Finite-Automata(DFA) called finite automata because finite amount of memory present in the form of states. For any Regular Language(RL) a DFA is always possible.
Let's see what information stored in the DFA (refer my colorful figure).
(note: In my explanation any number means zero or more times and Λ is null symbol)
State-1: is START state and information stored in it is even number of a has been come. And ZERO b.
Regular Expression(RE) for this state is = (aa)*.
State-4: Odd number of a has been come. And ZERO b.
Regular Expression for this state is = (aa)*a.
Figure: a BLUE states = EVEN number of a, and RED states = ODD number of a has been come.
NOTICE: Once first b has been come, move can't back to state-1 and state-4.
State-5: comes after Yellow b. Yellow b means b after odd numbers of a.
Once you gets b after odd numbers of a(at state-5) every thing is acceptable because there is self a loop for (b,a) at state-5.
You can write for state-5 : Yellow-b followed-by any string of a, b that is = Yellow-b (a + b)*
State-6: Just to differentiate whether odd a or even.
State-2: comes after even a then b then any number of b. = (aa)* bb*
State-3: comes after state-2 then first a then there is a loop via state-6.
We can write for state-3 comes = state-2 a (aa)* = (aa)*bb* a (aa)*
Because in our DFA, we have three final states so language accepted by DFA is union (+ in RE) of three RL (or three RE).
So the language accepted by the DFA is corresponding to three accepting states-2,3,5, And we can write like:
State-2 + state-3 + state-5
(aa)*bb* + (aa)*bb* a (aa)* + Yellow-b (a + b)*
I forgot to explain how Yellow-b comes?
ANSWER: Yellow-b is a b after state-4 or state-3. And we can write like:
Yellow-b = ( state-4 + state-3 ) b = ( (aa)*a + (aa)*bb* a (aa)* ) b
[ANSWER]
(aa)*bb* + (aa)*bb* a (aa)* + ( (aa)*a + (aa)*bb* a (aa)* ) b (a + b)*
English Description of Language: DFA accepts union of three languages
EVEN NUMBERs OF a's, FOLLOWED BY ONE OR MORE b's,
EVEN NUMBERs OF a's, FOLLOWED BY ONE OR MORE b's, FOLLOWED BY ODD NUMBERs OF a's.
A PREFIX STRING OF a AND b WITH ODD NUMBER OF a's, FOLLOWED BY b, FOLLOWED BY ANY STRING OF a AND b AND Λ.
English Description is complex but this the only way to describe the language. You can improve it by first convert given DFA into minimized DFA then write RE and description.
Also, there is a Derivative Method to find RE from a given Transition Graph using Arden's Theorem. I have explained here how to write a regular expression for a DFA using Arden's theorem. The transition graph must first be converted into a standard form without the null-move and single start state. But I prefer to learn Theory of computation by analysis instead of using the Mathematical derivation approach.
I guess this question isn't relevant anymore :) and it's probably better to guide you through it then just stating the answer, but I think I got a basic expression that covers it (it's probably minimizable), so i'll just write it down for future searchers
(aa)*b(b)* // for stoping at 2
U
(aa)*b(b)*a(aa)* // for stoping at 3
U
(aa)*b(b)*a(aa)*b((a)*(b)*)* // for stoping at 5 via 3
U
a(aa)*b((a)*(b)*)* // for stoping at 5 via 4
The examples (1 - 4) that you give there are not the language accepted by the DFA. They are merely strings that belong to the language that the DFA accepts. Therefore, they all fall in the same language.
If you want to figure out the regular expression that defines that DFA, you will need to do something called k-path induction, and you can read up on it here.