2 problem sheet two

88
МІЖНАРОДНА КОМІСІЯ НЕЗАЛЕЖНИХ ЕКСПЕРТІВ ПРОГРАМА РЕФОРМ ДЛЯ НОВОГО ПРЕЗИДЕНТА УКРАЇНИ Київ – 2010 ПРОПОЗИЦІЇ ДЛЯ УКРАЇНИ: 2010 – ЧАС ДЛЯ РЕФОРМ Співголови: Андерс Ослунд і Олександр Пасхавер

Upload: gouravjhangik350

Post on 10-Apr-2015

865 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 2 Problem Sheet Two

CS220 LANGUAGES, MACHINES AND

COMPUTATION

Problem Sheet 2

Problem 1 : A transducer is an FSM with output. Read from any book about Mealyand 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 orderbit. 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 theleft of the string.

Problem 3 : Let a1a2... be an input bit string. Design a transducer that computesthe parity of every substring of three bits. Design a transducer that computesthe parity of every substring of three bits. Specifically, the transducer shouldproduce 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 encodedusing 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 decodingstrings on {0, 1} into the original message. For example, the input 010011 shouldgenerate as output bad.

Problem 5 : Let x and y be two positive binary numbres. Design a transducer whoseoutput 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 aspossible and consisting entirely of the same symbol. For instance, the stringabbbaab contains a run of b’s of length three and a run of a’s of length two. FindDFAs for the following languages on {a, b}

1. L = {w : wcontains no runs of length less than four.}

2. L = {w : every run of a’s has length less than four. }

1

Page 2: 2 Problem Sheet Two

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, 001110and 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 rightend is different from the leftmost symbol.

Problem 12 : Let us define an operation truncate, which removes the rightmostsymbol from any string. For example, truncate(aaaba) is aaab. The operationcan 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 fortruncate(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 byextracting from w the letters in even numbered positionsl that is, if

w = a1a2a3a4...

then

even(w) = a2a4...

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 = {anbm : n ≥ 2, m ≥ 1}

2. L = {anb : n ≥ 0} ∪ {bna : 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 L1L2 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(a1a2a3a4a5a6...) = a3a6..

with the approprate extension of this definition to languages. Prove the closureof the family of regular languages under this operation.

2

Page 3: 2 Problem Sheet Two

Figure 1:

Problem 20 : For a string a1a2...an define the operation shift as

shift(a1a2...an) = a2...ana1

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

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

Show that regularity is preserved under the shift 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 shuffle of two languages L1 and L2 is defined as

shuffle(L1, L2) = {w1v1w2v2...wmvm : w1w2...wm ∈ L1, v1v2...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 areleft unchanged). Show that the family of regular languages is closed under theminus5 operation.

Problem 24 : Let G1 and G2 be two regular grammars. Show how one can deriveregular 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 finiteautomata shown in the next page.

3

Page 4: 2 Problem Sheet Two

Figure 2:

4