Automata Theory Problems and Exercises PDF Free
Automata Theory Problems and Exercises PDF Free
Homework Supplement
Chapter 1 : Fundamentals
i =0 i =0 i =0
1-2 (1.3) A palindrome can be defined as a string that reads the same forward and backward, or by the
following definition
a) ε is a palindrome
b) If a is any symbol, then the string a is a palindrome
c) If a is any symbol and x is a palindrome, then axa is a palindrome
d) Nothing is a palindrome unless it follows from a), b) and c)
Prove by induction, on the length |w| of the string w, that the two definitions are equivalent.
1-3 (1.7) Find the transitive closure, the reflexive and transitive closure, and the symmetric closure of
the relation {(1,2), (2,3), (3,4), (5,4)}.
1-4 (1.10) Prove that any subset of a countably infinite set is either finite or countably infinite.
2-1 (2.6) Describe in English the sets accepted by the finite automata whose transition diagrams are
given below:
a) 0 1 0,1
Start 1 0
A B C
this is discussed in class.
b) 0 1 1
1 0 1
Start A B C D
0
0
this looks easy but is a bit tricky.
c) Start A 1 1 D
0 0 0 0
1
C B
1
this is very difficult to describe.
2-3 Let Σ = {0, 1}. Consider the language L consisting of words that contain 010.
a) Draw a DFA A for L.
b) For each state q of the DFA A in part (a), precisely describe the set of words that lead the DFA from
its initial state to q.
2-4 (2.5) Give deterministic finite automata accepting the following languages over the alphabet
Σ={0,1}.
a) The set of all strings ending in 00.
b) The set of all strings with three consecutive 0’s.
c*) The set of all strings such that every substring of length three contains exactly one 0.
d) The set of all strings beginning with a 1 which, interpreted as the binary representation of an integer,
is congruent to zero modulo 5. (Hint: A left shift in binary is equivalent to multiplying the number by
two. Observe how different numbers multiplied by 2 behave modulo 5.)
e*) The set of all strings such that the 3rd symbol from the right end is 1.
f) The set of all strings excluding 011 and 10.
2-6 (2.4) Suppose δ is the transition function of a DFA. Prove that for any input strings x and y,
δ(q, xy)=δ( δ(q, x), y) . Hint: Use induction on |y|.
2-7 a) [1.6c,d,i,l]
3-1 For Σ = { a, b, c, d }, consider the set L of strings w such that the last symbol of w has not
appeared before. For example, the strings ε, c, adcdb, and ddbbca are in L, but the strings aba and
dbcdc are not in L. Give a nondeterministic finite automaton that accepts L. Try to take advantage of
nondeterminism as much as possible. Explain your answer.
3-2 (2.8) Give nondeterministic finite automata accepting the following languages :
a) The set of strings in {0,1}* such that some two 0’s are separated by a string whose length is 4i, for
some integer i≥0.
c*) The set of all strings of 0’s and 1’s such that the 3rd symbol from the right end is a 1. How does
your answer compare with the DFA of exercise 2.5e* (i.e. 2-4e* above) ?
3-3 For two words y and w, we say that y is a subword of w, if w = xyz for some words x and z. For
example, the word 011 has the following subwords: ε, 0, 1, 01, 11, and 011. For a language L, the set of
its subwords, denoted subwords(L), contains all the subwords of the words in L. That is, a word y
belongs to subwords(L) precisely when there exists a word w in L such that y is a subword of w.
Let L be a language, and let A be a DFA for L with states Q, initial state q0, final states F, and transition
function δ. Define an automaton B that accepts subwords(L). The automaton B can be a DFA or an
NFA or an ε-NFA. Ensure that B accepts all strings in subwords(L), and all strings accepted by B are
in subwords(L).
3-4 For the following NFA N, produce an equivalent DFA D. Draw D’s state diagram. Show your
solution, not just the final answer.
1
Start ε 0
q0 q1 q2
ε ε
1 1 1
0 0
q3 q4 q5
ε
4-1 (2.11) Describe in English the sets denoted by the following regular expressions :
a) (11+0)*(00+1)*
b*) (ε+1+11)(0+01+011)*
c) [00+11+(01+10)(00+11)*(01+10)]*
4-2 (2.10) Write regular expressions for each of the following languages over the alphabet {0,1}.
Provide justification that your regular expression is correct.
a) The set of all strings with at most one pair of consecutive 0’s and at most one pair of consecutive 1’s.
b) The set of all strings in which every pair of adjacent 0’s appears before any pair of adjacent 1’s.
c) The set of all strings not containing 101 as a substring.
4-3 Let Σ = {0, 1}. Consider the language L consisting of words that contain 010. Write a regular
expression for L.
4-4 Given the language L = { xyxR | x ∈{a, b}+, y∈{a, b}* , and xR is x written in reverse }
a) Describe the strings in L in English.
b) Show that L is regular by giving a regular expression for L.
4-5 Referring to exercise 3-3 , if L = 0+10*, write a regular expression that captures subwords(L).
4-6 (2.12) Construct finite automata equivalent to the following regular expressions :
a) 10+(0+11)0*1
b) 01[((10)*+111)*+0]*1
c) ((0+1)(0+1))*+((0+1)(0+1)(0+1))*
4-7 (2.13) Construct regular expressions corresponding to the state diagrams given below :
a) 0 b) Start
A 0
1
Start 1 1
A 1 0
B
0 1 1
0
C B
C 0
4-9 (2.24) Give Mealy and Moore machines for the following processes :
a) For input from (0+1)*, if the input ends in 101, output A; if the input ends in 110, output B;
otherwise, output C
b) For input from (0+1+2)* print the remainder modulo 5 of the input treated as a ternary (base 3, with
digits 0,1,2) number.
5-1 A word w is a palindrome if it is its own reverse (that is, w = wR). For example, 010 is a
palindrome, but 001 is not. Let Σ = {0, 1}. Prove that the set of palindromes P = { w | w in Σ* and w =
w R} is not regular using the Pumping Lemma.
5-2 Show that the language L = { wananwR | w∈{a, b}∗ and n>0 } is not regular using the
Pumping Lemma.
5-3 (3.1) Which of the following languages are regular sets? Prove your answer.
a) { 02n | n ≥ 1 }
b) { 0m1n0m+n | m ≥ 1 and n ≥ 1 }
c) { 0n | n is a prime }
d) the set of all strings that do not have three consecutive 0’s.
g) {xwxR | x, w in (0+1)+ }. xR is the string reversal of x.
6-1 (3.6) Show that L={ 0i1j | gcd(i,j)=1 } is not regular. Hint: Consider L ∩ 0 * 1 * .
6-2 (3.4) Let L be a regular set. Which of the following sets are regular? Justify your answers.
a) { a1a3a5 … a2n-1 | a1a2a3a4…a2n is in L }
b) { a2a1a4a3a6a5…a2na2n-1 | a1a2a3a4…a2n is in L }
c) CYCLE(L) = { x1x2 | x2x1 is in L for strings x1 and x2 }
d) MAX(L) = { x in L | for no y other than ε is xy in L }
e) MIN(L) = { x in L | no proper prefix of x is in L }
f) INIT(L) = { x | for some y, xy is in L }
g) LR = { x | xR is in L } (This is an example in the lecture. Try to do this by NFA.)
h) {x | xxR is in L }
6-3 Are the following languages regular or not regular ? Prove your answer.
a) L1 = { 0m1n | m ≠ 2n } Hint: Consider L ∩ 0 * 1 * .
b) L2 = { w | w∈{a, b}* and w ≠ wR } Hint: Consider L .
c) (3.1h) L3 = {xxRw | x, w in (0+1)+ }. xR is the string reversal of x. (Note: very tricky.)
Hint: Consider L3 ∩ 10 * 110 * 11
6-5 Let Σ = {a, b}. Let L1 be the set of words w that contain an even number of a’s. Let L2 be the set
of words w that end with b. Let L3 = L1 ∩ L2.
a) Draw a DFA A for L1 with 2 states.
b) Draw a DFA B for L2 with 2 states.
c) Draw a DFA C for L3 with 4 states using the product construction.
0 1 0 1 0 1
1
0 0 0
Start A B C D E F G H
0 1 1 0
1 1
b*) Repeat part a) assuming H is the start state instead.
7-4 (3.26)
a) What are the equivalence classes of RL in the Myhill-Nerode theorem for
L = { 0n1n | n ≥ 1 } ?
b) Use your answer in (a) to show L = { 0n1n | n ≥ 1 } is not regular.
c) Repeat (a) for { x | x has an equal number of 0’s and 1’s }.
8-3 Show that the language L = { wananwR | w∈{a, b}∗ and n>0 } is context free by giving a
context free grammar for L.
8-8 Consider the grammar G with a single variable R, which is also the start variable, over the alphabet
{ 0, 1, +, ∗, (, ) } :
R 0 | 1 | R∗ | R + R | (R)
a) Show a left-most derivation of the word 0+(1∗+0)
b) Show a parse tree for the word (0+1)∗+1
c) Is G ambiguous? Justify your answer in one or two sentences, no proof is needed.
d) If L(G) regular? Justify your answer in one or two sentences, no proof is needed.
8-9 Construct a context free grammar equivalent to the regular expression (a+bab)*(b+a)
9-2 Referring to the grammar G described in exercise 8-8 , is G in Chomsky Normal Form?
9-4 (4.11) Suppose G is a CFG and w, of length p, is in L(G). How long is a derivation of w in G if
a) G is in CNF,
b) G is in GNF.
9-5 (4.12) Let G be the CFG generating well-formed formulas of propositional calculus with predicates
p and q :
S ~S | [S⊃S] | p | q
The terminals are p, q, ~, [, ], and ⊃. Find a Chomsky normal-form grammar generating L(G).
9-6 (4.14) Find a Greibach normal-form grammar equivalent to the following CFG :
S AA | 0
A SS | 1
11-1 (6.1) Show that the following are not context-free languages:
a) { aibjck | i<j<k }
b) { aibj | j = i2 }
c) { ai | i is a prime }
d) the set of strings of a’s, b’s and c’s with an equal number of each
e) { anbncm | n≤m≤2n }
11-2 Prove that the following languages are not CFLs using the pumping lemma for CFLs :
a) L1 = { aibjck | i = k and j > i }
b) L2 = { 1k | k=n2 and n ≥ 0 }
c) L3 = { ai bj ci dj | i, j ≥ 0 }
12-3 For each of the following languages, determine whether it is (I) regular, (II) not regular but
context-free, or (III) not context-free. Prove your answer.
a) L1 = { aibjck | i < j < k }
b) L2 = { ai bi cj dj | i, j ≥ 0 }
c) L3 = { w | w = ai bi cj dj where i, j ≥ 0 and
w does not contain the substring bccd }
i j
d) L4 = { a b | 2i ≠ 3j }
e) L5 = { 0n 02n 03n | n ≥ 0 }
f) L6 = { xy | x, y ∈{0, 1}∗ and x ≠ y }
13-2 Consider the Turing machine with states {q0, q1, q2, qf }, input alphabet {0, 1}, tape alphabet {0,
1, B}, initial state q0, final state qf , blank symbol B, and transition function given by:
δ(q0, 0) = (q1, 1, R);
δ(q1, 1) = (q2, 0, L);
δ(q2, 1) = (q0, 1, R);
δ(q1, B) = (qf, B, R)
Clearly describe the language accepted by this machine.
13-4 Describe a standard (deterministic, single-tape) Turing machine that accepts the following
language:
L = { 0p | p is not a prime }
14-2 (7.3) Show that if L is accepted by a k-tape, p-dimensional, nondeterministic TM with m heads
per tape, then L is accepted by a deterministic TM with one semi-infinite tape and one tape head.
14-4 A k-head (deterministic) Turing machine has k heads reading cells of a single tape. A move
depends on the current state and the symbols read by the heads. In one move, the machine can update
the state, write a new symbol on each of cells scanned by the heads, and move each head left, right, or
keep it stationary.
Since several heads may be scanning the same cell, assume that the heads are numbered 1 through k, and
the symbol written by the highest numbered head scanning a given cell is the one that is actually written
in that cell. Prove that the languages accepted by k-head TMs are the same as those accepted by standard
TMs.
14-5 a) [3.9]
15-1 (8.1) Suppose the tape alphabets of all Turing machines are selected from some infinite set of
symbols a1, a2, a3, … . Show how each TM may be encoded as a binary string.
15-2 (8.2) Which of the following properties of recursively enumerable sets are themselves recursively
enumerable ?
a) L contains at least two strings
b) L is infinite
c) L is a context-free language
d) L = LR
15-4 (8.7) Show that the following problems about programs in a real programming language are
undecidable :
a) Whether a given program can loop forever on some input
b) Whether a given program ever produces an output
c) Whether two programs produce the same output on all inputs