Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Exercises
n 2,
3
k=1
k>
3
n3n.
4
resulting map by two colors in such a way that any two neighboring
states will have different colors.
7. There are n lines in the plane in general position (i.e., no two of
them are parallel and no three meet at the same point). Prove that
the number of states in the resulting map is n(n+1)
+ 1.
2
8. There are n pairs of socks of different colors in a drawer. How
many need to be drawn to make sure that they will contain at least
one pair?
9. Let a1 , a2 , . . . , an be any integers. Show that there exist 1
i j n such that the sum ai + ai+1 + . . . + aj is divisible by n.
10. Prove that, for any finite set of (at least two) people, there are
at least two people in the set who know exactly the same number of
people from the set. (Assume that if A knows B then B knows A).
11. Prove that, in any group of six people or more, either there are
three each of whom knows both of the two others or there are three
each of whom knows none of the two others.
12. For every subset of {rreflexive, symmetric, transitive}, construct a relation with the properties in this partial set, but not with
the other properties.
13. For each of the following relations on a set A, determine
whether it is reflexive, symmetric, transitive:
(a) A the set of integers, aRb if b a is divisible by m (where m
is a fixed positive integer)
(b) A the set of integers, aRb if |b a| 5.
(c) A the set of reals, aRb if |b a| 0.001.
(a) Show that fi is recursive iff (M n )ii > 0 for some positive integer n.
(b) Show that the set of functions that have to be put in every
program that uses fi is: {fj : there exists n such that Mijn > 0}.
17. A path in a directed graph is Hamiltonian if it passes exactly
once through each vertex of the graph. (It is not necessary that there
exists an edge from last vertex of the path to the first). Prove by
induction that for any finite graph the following is true: If between
every pair of vertices there is an edge in at least one direction, then
the graph contains a Hamiltonian path.
18.
(a) Present a machine which, given a sequence of digits representing a non-negative integer in base 10, starting with the least
significant digit, determines whether this integer is even or odd.
(b) Same as the preceding part if the digits are given starting with
the most significant.
(c) Same as part (a) for the problem of divisibility by 125.
(d) Same as part (a) for the problem of divisibility by 3.
19.
of the complex plane, with the operations of addition and multiplication. An element z Z[i], distinct from 0, 1, i, may be either
prime or composite; it is composite if it may be written as a product
of two such numbers, and prime otherwise.
(a) Present an algorithm to decide whether a given z Z[i] is prime
or not.
(b) Show that every element z Z[i], distinct from 0, 1, i, is
a product of finitely many primes. Present an algorithm for
finding such a factorization.
20. Show that the 1-dimensional tiling problem, namely that of
tiling the line by finitely many types of unit intervals, is decidable.
4
3
25.
(a) xy = yx.
(b) xyx = yxy.
(c) xyx = yxy 2 .
(d) xy 2 x = yx2 y.
26.
b0 = 1
bn = bn1 an1 ,
n1.
Let L1 , L2 , L3 be languages.
C
possible that LC =
6 (L ) ? that LC = (L )C ?
31.
32.
Prove that:
(a) if L then (L ) = L .
Regular Expressions
(d) (a ) (b ) (ab ) (a b ) .
(e) a bb a.
(f) (a b) (ba ) .
(g) (a b) a(a b) .
35. Let = {0, 1}. Show that the following languages over are
regular:
(a) The collection of all words containing an even number of 0s.
(b) The collection of all words containing an odd number of 0s.
(c) The collection of all words in which the number of 0s is divisible
by 3.
(d) The collection of all words containing at least three 0s.
(e) The collection of all words in which the block 01 appears exactly
once.
(f) The collection of all words in which the block 00 appears exactly
once.
(g) The collection of all words in which the block 000 appears exactly once.
(h) The collection of all words ending with 10.
(i) The collection of all words not ending with 10.
36. How many words of length n do the languages, corresponding
to the following regular expressions, contain? (In each case is the
set of letters appearing in the expression.)
(a) (01 ) .
(b) 0 1 .
(c) 0 1 2 .
7
(d) 0 1 0 .
(e) 0 1 2 3 4 5 6 .
(f) (0 10) .
(g) (0 11 22) .
(j) (1 011 ) .
a .
(c) (01 ) .
(d) (00 1 1 0 102 1) .
a
a
b
b
a
b
a,b
a,b
a,b
a
10
(b)
a,b
a,b
a
a,b
b
a
b
(c)
a,b
a,b
a
a
(d)
a,b
a,b
a,b
(e)
a
b
a
a,b
11
(f)
a,b
b
a
a
a
b
(g)
a
a
b
a
a
a,b
(h)
b
b
a
a
a
(i)
a
a
b
b
b
a
b
12
42. Let = {a, b}. Construct DFAs accepting the following languages:
(a) All words of even length.
(b) All words of odd length.
(c) All words of length 2 modulo 5.
(d) All words in which the number of as is 2 modulo 5.
(e) All words in which the number of as is 2 modulo 3 and the
number of bs is 2 or 3 modulo 4.
(f) Any given finite language.
(g) Any given language whose complement is finite.
(h) All words not containing ba as a subword.
(i) All words not ending with aab.
(j) All words ending with neither ab nor aabb.
(k) All words containing abab as a subword.
(l) All words containing both ab and ba as subwords.
(m) All words containing neither a2 nor b2 as subwords.
(n) All words in which the third letter from the right is b.
(o) All words with at most one occurrence of a2 and one occurrence
of b2 .
a
b
(b)
13
(c)
(d)
aba
b
bb
(e)
a
a
b
b
a
(f)
a
b
a
a
a
14
(g)
bb
a,aba
aaa
,ba
ab
(h)
ab
,a
3
a
a,b
a
a,ba
ab
b
,b
44.
(a1) Construct an NFA accepting the language consisting of all
words over {a, b} ending with aaba.
(a2) Construct a DFA accepting the same language.
(b) Do the same for the language (ab a3 aba) .
45. Construct NFAs accepting the following languages:
(a) (101 010) .
(e) ((0 1 0 ) 1) .
(c)
, a
;
a, b
16
(d)
b
a,b
a
3
3
ba
(j) L0 = {w1 2 : w1 L, w1 , }.
50. Given two automata M1 , M2 , with state sets Q1 , Q2 , respectively, construct an automaton M3 whose state set is Q1 Q2 such
that L(M3 ) = L(M1 ) L(M2 ).
51. A language L is absolute if there exists a positive integer l such
that, for any word w , belonging to L depends only on the l
last letters of w.
17
w 1 , 1 ,
w1 , w2 1 .
(c) a (b a3 b2 )b .
(d) a bb (a a2 ba)ba .
(e) ba (a bb)a b
(f) ab(((ab) b3 ) a) .
(k) ((a b) ( c) ) .
(l) a (ab ba )b .
60. Use the idea of the proof that every language accepted by
an FA is regular to find regular expressions corresponding to the
languages accepted by the following automata:
20
(a)
a, b
;
a, b
(b)
a
a, b
;
a, b
b
(c)
a
b
b
b
b
a
(d)
b
b
b
a
21
(e)
a, b
a
;
a
a
(f)
a, b
a
a
a, b
b
(g)
a
a
;
a, b
b
a
(h)
a
b
a, b
a b
;
b
Pumping Lemma
(b) {wk : w },
(|| 2).
(|| 2, k 2).
23
(c) {wwR : w },
(|| 2).
3 +2n2
: n 0}.
(b) {1 2n 3 : 1 , 2 , 3 , 1 6= 2 , 1 6= 3 , 2 6= 3 , n 2}.
(d) All words in {a, b} in every proper prefix of which the difference
between the number of as and the number of bs does not
exceed 100 in its absolute value. (Thus, for the word itself the
difference in question may be 101.)
(e) {am bn : m, n 0, m n 2m}.
(f) All words over the Hebrew alphabet starting with a final letter
and ending with a non-final letter.
(g) All words over the Hebrew alphabet in which no letter occurs
more than three times.
72. Given a set of non-negative integers, the set of their expansions
in base 10 forms a partial language of {0, 1, . . . , 9} . For each of the
following sets show that the corresponding language is regular or
not (as indicated):
(a) All even numbers (regular).
(b) All numbers divisible by 10 (regular).
(c) All numbers congruent to 333 modulo 625 (regular).
24
(d) All numbers divisible by 3 (regular. Hint: You may use the
fact that an integer is divisible by 3 if and only if the sum of
its digits is such.)
(e) All numbers divisible by 11 (regular. Hint: A number is divisible
by 11 if and only if the alternating sum of its digits is such. For
example: 379181737 is divisible by 11 since 3 7 + 9 1 + 8
1 + 7 3 + 7 = 2 11.)
(f) All numbers congruent to r modulo d, where 0 r < d (regular).
(g) All powers of 10 (regular).
(h) All powers of 2 (not regular. Hint: Use the pumping lemma
and the fact that no power of 10 but 100 is a power of 2.)
(i) All perfect squares (not regular. Hint: Start with special perfect
squares.)
(j) {an : n 0} where a0 = 3 and an = a2n1 for n 1 (not
regular).
(k) {2m 5n : m, n 0, |m n| 10} (regular).
73. With definitions as in the preceding exercise, determine whether
the following sets are regular:
(a) {10m + 10n + 1 : m > n 1}.
(b) {102n + 10n + 1 : n 1}.
(c) {27 10m + 19 10n + 53 : m > n + 3, n > 2}.
(d) {27 10m 19 10n 53 : m max(2, n)}.
2
n = 0,
0,
an1 + 1,
n 1, an1 has an odd number of digits,
an =
an1 + 2,
n 1, an1 has an even number of digits.
25
ratios for L. For example, Ra,b ({a, b} ) = [0, ] and Ra,b (L) = [, ]
if L = {w {a, b} : Ra,b (w) } (for any 0 ).
(a) Show that, if F is any finite set of (non-negative) rationals,
then there exists a regular language L with Ra,b (L) = F .
Context-Free Grammars
(e) S SS | aS | ab.
(f) S | aaSb | bbSa.
(g) S bA | abA ,
A | S.
(h) S aAb ,
A | S | Sb.
(i) S aAb | bAa ,
A | S | aSa.
(j) S aA | bS | b ,
A aB | bA ,
B aS | bB | a.
26
(k) S aA | bB ,
A bB ,
B | S.
(l) S AB ,
A aS | bB | ,
B bS | aA | .
(m) For any alphabet = {1 , 2 , . . . , m }:
S ,
S i Sj , 1 i, j m.
m m
(k)
m=2 L ((a b) (b a) ).
m
m
(l)
m=0 L ((a b) c(b a) ).
2m
(m)
a(a c)m ).
m=0 L (a b
(r) All words in {a, b} not containing the word aaa as a subword.
(s) {w : wR 6= w} ( an arbitrary alphabet).
(t) All words in {a, b, c, d} starting and ending with an a such that
between any two consecutive as there is an even number of bs.
(u) {avbw : v, w {a, b} , |v| = |w|}.
(v) {wcwR : w {a, b} }.
Regular Grammars
b
b
c
a, b
(b)
b
a
b
a
b
b
a
a
30
(c)
b
a
a
b
a
a
a
b
ba
b
a
31
(b)
a a
a
a
b
c
b
a
(c)
b, c
a, b, c
c
a
10
Pushdown Automata
32
(b)
a, |a
, |
, |
b, a|
, |
, |
a, |a2
(c)
a, |a
a, a|
a2 b, |
b, |a
b, a|
(d)
a, |a3
2
a, a |
a, |a4
a, a2 |
a, a4 |
(e)
a, |a2
a, |a
a, |a
c, a|
ab, a|
b, a2 |
33
(f)
c, a2 |
a, |a
b, |a
b, |a3
(g)
b, a|
a, |a b, a|
c, a|
c, |
c, |
c, a|
34
(b)
a, |a
, |
b, a|
11
91. Use the property of closure under union to show that the following languages are context free:
(a) {am bn : m 6= n}.
(e) {www : w },
(|| 2).
(c) {a2 3
: l, m, n 0}.
12
Turing Machines
99. For each of the following Turing machines, determine for which
inputs they eventually halt, for which they hang and for which they
never halt. In all cases = {B}.
(a) = {a, b}.
a|a, R
b|a, L
(b) = {a, b}.
a|b, R
b|a, L a|a, R
b|a, R
37
a|b, R
c|a, L
b|c, R
b|B,
b|B, L
B|a,
c|a, L
B|b, L
a|a, R
B|a, L
b|a, R
38
(a)
a|b, R
b|B, R
b|b, L
B|a, L
B|b, R
(b)
a|b, R
a|a, L
a|a, L
b|a, L
a|b, L
B|B, L
b|a, R
(c)
a|a, R b|b, R
b|b, R
B|B,
a|b, R
c|b, L
b|b, L
(d)
a|b, R
b|b, R
b|a, R
B|B, L
a|b, L
b|b,
(e)
a|b, R
b|a, R
B|B,
39
(f)
|, R
a|B, R
B|B, R
B|B, L
|, L
b|B, L
B|B,
B|B,
(g)
a|b, R
B|B,
b|a, L
|w| 2,
w,
(a) f (w) =
w3 , |w| 3, w = 1 2 . . . n .
(b) f (w) = 1 2 4 5 7 8 . . . ,
w = 1 2 . . . n .
(c) f (w) = w R .
(d) f replaces each occurrence of ab by a c (for example, f (baabaabb) =
bacacb).
wd, otherwise.
wgood,
(g) f (w) =
wbad,
40
wgreater, |w|a > |w|b ,
wless,
|w|a < |w|b ,
(h) f (w) =
wequal,
|w|a = |w|b .
102. Explain how we can, given any homomorphism (see exercise 52) from to , construct a Turing machine computing
the homomorphism. Exemplify for the homomorphism defined by
h(a) = cacb, h(b) = bab.
103. Construct Turing machines accepting the following languages:
(a) a b2 a.
(b) a b a b .
(c) {an bn : n 0}.
(d) {an bn cn : n 0}.
(e) {an b2n cn+1 : n 0}.
(f) {am bm an bn : m, n 0, m 6= n}.
(g) {al bm an : m = l + n}.
(i) The language consisting of all words over {a, b} in which the
number of as is equal to the number of bs and the number of
as in each prefix is not smaller than the number of bs in the
same prefix.
(j) {ap : p is prime}.
n
B|0,
|, R
0|?, R
1|1, R
B|1, L
?|1, R
|, L
n Z+ .
n Z+ .
m, n Z+ .
m, n Z+ .
(b) {w : wR 6= w}.
43