Homework 7
Homework 7
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
1
Homework 7 Ren Shixin
(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 )