0% found this document useful (0 votes)
54 views3 pages

Homework 7

Uploaded by

shixinren813
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Homework 7

Uploaded by

shixinren813
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Formal Languages and Automata Ren Shixin

2024 Autumn 2023012444

Homework 7

Problem 1. Design a PDA to accept each of the following languages. You may
accept either by final state or by empty stack, whichever is more convenient.
(a) (Exercise 6.2.1 (b)) The set of all strings of 0’s and 1’s such that no prefix
has more 1’s than 0’s.
(b) (Exercise 6.2.2 (b)) The set of all strings with twice as many 0’s as 1’s.
(c) Strings w over {a, b, c} where the numbers of a’s and b’s are the same and
there are no consecutive c’s.
Solution. (a)
We construct this PDA P = (Q = {S, T }, Σ = {0, 1}, Γ = {0, 1, Z0 }, δ, q0 =
S, Z0 , F = {T }), and δ is shown below

δ(S, 0, Z0 ) = {(S, 0Z0 )}


δ(S, 1, 0) = {(S, ϵ)}
δ(S, 0, 0) = {(S, 00)}
δ(S, ϵ, Z0 ) = {(T, ϵ)}
δ(S, ϵ, 0) = {(T, ϵ)}

P is accepted by final state.


(b) We construct this PDA P = ({q0 , q1 }, Σ = {0, 1}, Γ = {0, 1, Z0 }, δ, q0 , Z0 ),
and δ is shown below

δ(q0 , 0, Z0 ) = {(q0 , 0Z0 )}


δ(q0 , 1, Z0 ) = {(q1 , Z0 )}
δ(q0 , 0, 0) = {(q0 , 00)}
δ(q0 , 1, 0) = {(q1 , 0)}
δ(q0 , 0, 1) = {(q1 , 0)}
δ(q0 , 1, 1) = {(q1 , 1)}
δ(q1 , 0, 0) = {(q1 , 00)}
δ(q1 , 0, 1) = {(q1 , ϵ)}
δ(q1 , 1, 0) = {(q0 , ϵ)}
δ(q1 , 1, 1) = {(q0 , 11)}
δ(q1 , 0, Z0 ) = {(q1 , 0Z0 )}
δ(q1 , 1, Z0 ) = {(q0 , 1Z0 )}
δ(q0 , ϵ, Z0 ) = {(q0 , ϵ)}

P is accepted by empty stack.


(c)
We construct this PDA P = ({q0 , q1 , q2 }, Σ = {a, b, c}, Γ = {a, b, Z0 }, δ, q0 , Z0 )
and δ is shown below

1
Homework 7 Ren Shixin

δ(q0 , a, Z0 ) = {(q0 , aZ0 )}


δ(q0 , b, Z0 ) = {(q0 , bZ0 )}
δ(q0 , a, a) = {(q0 , aa)}
δ(q0 , a, b) = {(q0 , ϵ)}
δ(q0 , b, a) = {(q0 , ϵ)}
δ(q0 , b, b) = {(q0 , bb)}
δ(q0 , c, Z0 ) = {(q1 , Z0 )}
δ(q0 , c, a) = {(q1 , a)}
δ(q0 , c, b) = {(q1 , b)}
δ(q1 , a, a) = {(q0 , aa)}
δ(q1 , a, b) = {(q0 , ϵ)}
δ(q1 , b, a) = {(q0 , ϵ)}
δ(q1 , b, b) = {(q0 , bb)}
δ(q0 , ϵ, Z0 ) = {(q2 , ϵ)}
δ(q1 , ϵ, Z0 ) = {(q2 , ϵ)}

P is accepted by empty stack.

Problem 2. (Exercise 6.2.6) Consider the PDA


( )
P = {q, p}, {0, 1}, {Z0 , X}, δ, q, Z0 , {p}

having the following transition function:

1. δ(q, 0, Z0 ) = {(q, XZ0 )}.


2. δ(q, 0, X) = {(q, XX)}.
3. δ(q, 1, X) = {(q, X)}.
4. δ(q, ϵ, X) = {(p, ϵ)}.

5. δ(p, ϵ, X) = {(p, ϵ)}.


6. δ(p, 1, X) = {(p, XX)}.
7. δ(p, 1, Z0 ) = {(p, ϵ)}.

(a) Convert P to another PDA P1 that accepts by empty stack the same
language that P accepts by final state; i.e., N (P1 ) = L(P ).
(b) Find a PDA P2 such that L(P2 ) = N (P ); i.e., P2 accepts by final state
what P accepts by empty stack.
Solution. (a)
We construct PDA P1 = ({q, p, q0 , q1 }, {0, 1}, {Z0 , X, X0 }, δ1 , q0 , X0 ) and δ1
is shown below

2
Homework 7 Ren Shixin

δ1 (q0 , ϵ, X0 ) = {(q, Z0 X0 )}
δ1 (q, 0, Z0 ) = {(q, XZ0 )}
δ1 (q, 0, X) = {(q, XX)}
δ1 (q, 1, X) = {(q, X)}
δ1 ((q, ϵ), X) = {(p, ϵ)}
δ1 (p, ϵ, X) = {(q1 , ϵ), (p, ϵ)}
δ1 (p, ϵ, X0 ) = {(q1 , ϵ)}
δ1 (p, ϵ, Z0 ) = {(q1 , ϵ)}
δ1 (p, 1, X) = {(p, XX)}
δ1 (p, 1, Z0 ) = {(p, ϵ)}
δ1 (q1 , ϵ, X) = {(q1 , ϵ)}
δ1 (q1 , ϵ, X0 ) = {(q1 , ϵ)}
δ1 (q1 , ϵ, Z0 ) = {(q1 , ϵ)}
it follows:
1. δ1 (q0 , ϵ, X0 ) = {(q, Z0 X0 )}
2. ∀x ∈ {p, q}, y ∈ {0, 1, ϵ}, z ∈ {Z0 , X}, δ(x, y, z) ⊂ δ1 (x, y, z)
3. ∀x ∈ {Z0 , X, X0 }, (q1 , ϵ) ∈ δ1 (p, ϵ, x)
4. ∀x ∈ {Z0 , X, X0 }, δ1 (q1 , ϵ, x) = (q1 , ϵ)
(b)
We construct PDA P1 = ({q, p, q0 , qf }, {0, 1}, {Z0 , X, X0 }, δ1 , q0 , X0 , {qf })
and δ1 is shown below
δ1 (q0 , ϵ, X0 ) = {(q, Z0 X0 )}
δ1 (p, ϵ, X0 ) = {(qf , ϵ)}
δ1 (q, ϵ, X0 ) = {(qf , ϵ)}
δ1 (q, 0, Z0 ) = {(q, XZ0 )}
δ1 (q, 0, X) = {(q, XX)}
δ1 (q, 1, X) = {(q, X)}
δ1 (q, ϵ, X) = {(p, ϵ)}
δ1 (p, ϵ, X) = {(p, ϵ)}
δ1 (p, 1, X) = {(p, XX)}
δ1 (p, 1, Z0 ) = {(p, ϵ)}
it follows:
1. δ1 (q0 , ϵ, X0 ) = {(q, Z0 X0 )}
2. ∀a ∈ {p, q}, b ∈ {0, 1, ϵ}, c ∈ {X, Z0 }, δ(a, b, c) ⊂ δ1 (a, b, c)
3. ∀a ∈ {p, q}, (qf , ϵ) ∈ δ1 (a, ϵ, X0 )

You might also like