You are on page 1of 4

CS220 LANGUAGES, MACHINES AND

COMPUTATION

Problem Sheet 2
Problem 1 : A transducer is an FSM with output. Read from any book about Mealy
and Moor machines and prepare a writeup.
Problem 2 : The two’s complement of a binary string, representing a positive integer,
is formed by first complementing each bit, then adding one to the lowest order
bit. Design a transducer for translating bit strings into their two’s complement,
assuming that the binary numbe is represented as is with lower order bits at the
left of the string.
Problem 3 : Let a1 a2 ... be an input bit string. Design a transducer that computes
the parity of every substring of three bits. Design a transducer that computes
the parity of every substring of three bits. Specifically, the transducer should
produce output

π1 = π2 = 0, πi = (ai−2 + ai−1 + ai )mod 2, i = 3, 4, ...

For example, the input 110111 should produce 000001.


Problem 4 : Digital computers normally represent all information by bit strings,
using some type of encoding. For example, character information can be encoded
using the well known ASCII system. For this exercise, consider two alphabets
{a, b, c, d} and {0, 1}, respectively, and an encoding from the first to the second,
defined bya → 00, b → 01, c → 10, d → 11. Construct a transducer for decoding
strings on {0, 1} into the original message. For example, the input 010011 should
generate as output bad.
Problem 5 : Let x and y be two positive binary numbres. Design a transducer whose
output is max(x, y).
Problem 6 : Give a grammar for the set integer numbers in C and Pascal.
Problem 7 : Design an accepter for integers in C and Pascal.
Problem 8 : Give a grammar that generates all reals in C.
Problem 9 : Find DFAs for the following languages on Σ = {a, b}
1. L = {w : |w|mod 3 = 0}
2. L = {w : |w|mod 5 6= 0}
3. L = {w : na (w)mod 3 > 1}
4. L = {w : na (w)mod 3 > nb (w)mod3}
5. L = {w : (na (w) − nb (w))mod 3 > 0}
Problem 10 : A run in a string is a substring of length at least two, as long as
possible and consisting entirely of the same symbol. For instance, the string
abbbaab contains a run of b’s of length three and a run of a’s of length two. Find
DFAs for the following languages on {a, b}
1. L = {w : wcontains no runs of length less than four.}
3. L = {w : there are at most two runs of a’s of length three. }
Problem 11 : Consider the set of strings on {0, 1} defined by the requirements below.
For each construct an accepting dfa.
1. Every 00 is followed immediately by a 1. For example, the strings 101, 0010,
0010011001 are in the languages, but 0001 and 00100 are not.
2. The leftmost symbol differs from the rightmost one.
3. Every substring of four symbols has at most two 0’s. For example, 001110
and 011001 are in the language, but 10010 is not since one of its substrings,
0010, contains three zeros.
4. All strings of length five or more in which the fourth symbol from the right
end is different from the leftmost symbol.
Problem 12 : Let us define an operation truncate, which removes the rightmost
symbol from any string. For example, truncate(aaaba) is aaab. The operation
can be extended to languages by

truncated(L) = {truncate(w) : w ∈ L}

Show how, given a DFA for any regular language L, one can construct a DFA for
truncate(L). From this, prove that if L is a regular language not containing λ,
then truncate(L) is also regular.
Problem 13 : Show that if L is regular, so is LR .
Problem 14 : Let L be any language. Define even(w) as the string obtained by
extracting from w the letters in even numbered positionsl that is, if

w = a1 a2 a3 a4 ...

then

even(w) = a2 a4 ...

Corresponding to this, we can define a language

even(L) = {even(w) : w ∈ L}

Prove that if L is regular, so is even(L).


Problem 15 : Find the minimal DFA for the following languages.
1. L = {an bm : n ≥ 2, m ≥ 1}
2. L = {an b : n ≥ 0} ∪ {bn a : n ≥ 1}
3. L = {an : n ≥ 0, n 6= 3}
Problem 16 : Minimize the states in the DFA depicted in the following diagram.
Problem 17 : Is the following true: If L1 and L1 L2 are regular, so is L2 ?
Problem 18 : The head of a language is the set of all prefixes of its strings, that is,

head(L) = {x : xy ∈ L for some y ∈ Σ∗ }.

Show that the family of regular languages is closed under this operation.
Problem 19 :Define an operation third on strings and the language as

third(a1 a2 a3 a4 a5 a6 ...) = a3 a6 ..

with the approprate extension of this definition to languages. Prove the closure
Figure 1:

Problem 20 : For a string a1 a2 ...an define the operation shif t as

shif t(a1 a2 ...an ) = a2 ...an a1

From this, we can define the operation on a language as

shif t(L) = {v : v = shif t(w) for some w ∈ L}

Show that regularity is preserved under the shif t operation.


Problem 21 :Define

exchange(L) = {v : v = exchange(w) for some w ∈ L}.

Show that the family of regular languages is closed under exchange.

Problem 22 : The shuf f le of two languages L1 and L2 is defined as

shuf f le(L1, L2 ) = {w1 v1 w2 v2 ...wm vm : w1 w2 ...wm ∈ L1 , v1 v2 ...vm ∈ L2 ,


for all wi , vi ∈ Σ∗ }

Show that the family of regular languages is closed under the shuffle operation.
Problem 23 :Define an operation 5 on a language L as the set of all strings of L
with the fift symbol from the left removed (stringsof length less than five are
left unchanged). Show that the family of regular languages is closed under the
minus5 operation.
Problem 24 : Let G1 and G2 be two regular grammars. Show how one can derive
regular grammars for the languages L(G1 ) ∪ L(G2 ), L(G1 )L(G2 ), and L(G1 )∗
from G1 and G2 .
Problem 25 : Describe informally the languages accepted by the deterministic finite
automata shown in the next page.
Figure 2:

You might also like