You are on page 1of 3

CSE 2002: Theory of Computation and Compiler Design

Instructor: Ashwin Ganesan


Practice problems on DFA and NFA

1 (Deterministic) Finite Automata


1. Recall the following inductive definition of the extended transition function: δ̂(q, w) = q
if w =  and δ̂(q, w) = δ(δ̂(q, x), a) if w = xa for some x ∈ Σ∗ and a ∈ Σ. However, we
can informally think of δ̂ as describing what happens along a path with a certain string of
labels, and if so, then it should not matter how we break the input string in the definition
of δ̂. Show that in fact, δ̂(q, xy) = δ̂(δ̂(q, x), y) for any state q and strings x and y. Hint:
Perform an induction on |y|. [1, Ex. 2.2.2]

2. Give DFA’s 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 (not necessarily at the end).
(c) The set of strings with 011 as a substring. [1, Ex. 2.2.4]

3. Give a DFA which accepts the following language over the alphabet {0, 1}: The set of
all strings beginning with a 1 that, when interpreted as a binary integer, is a multiple of
5. For example, strings 101, 1010, and 1111 are in the language, and 0, 100, and 111 are
not. [1, Ex. 2.2.6a]

4. Let A = (Q, Σ, δ, q0 , {qf }) be a DFA, and suppose that for all a in Σ we have δ(q0 , a) =
δ(qf , a).

(a) Show that for all w 6=  we have δ̂(q0 , w) = δ̂(qf , w).


(b) Show that if x is a nonempty string in L(A), then for all k > 0, xk (i.e. x written k
times) is also in L(A).

[1, Ex. 2.2.9]

5. Consider the DFA with the following transition table:

0 1
→A A B
∗B B A

Informally describe the language accepted by the DFA, and prove by induction on the
length of an input string that your description is correct. Hint: When setting up the
inductive hypothesis, it is wise to make a statement about what inputs get you to each
state, not just what inputs get you to the accepting state. [1, Ex. 2.2.10]

Page 1 of 3
6. The following language is the intersection of two simpler languages:

{w : w has exactly two a’s and at least two b’s}.

Construct the DFAs for the two simpler languages, then combine them using the product
construction discussed in lectures to obtain the DFA for the given language. [2, Ex.
1.4b]

7. The following language is the intersection of two simpler languages:

{w : w has an even number of a’s and each a is followed by at least one b}.

Construct the DFAs for the two simpler languages, then combine them using the product
construction discussed in lectures to obtain the DFA for the given language. [2, Ex.
1.4d]

8. The following language is the complement of a simpler language:

{w : w does not contain the substring ab}.

Construct the DFA for the simpler language, and then modify it to obtain a DFA for the
given language. Hint: Replace the set of states F by its complement Q − F to obtain a
machine for the complement language. [2, Ex. 1.5a]

9. The following language is the complement of a simpler language:

{w : w does not contain the substring baba}.

Construct the DFA for the simpler language, and then modify it to obtain a DFA for the
given language. Hint: Replace the set of states F by its complement Q − F to obtain a
machine for the complement language. [2, Ex. 1.5b]

2 Nondeterministic Finite Automata (NFA)


1. Convert to a DFA the following NFA:

0 1
→p {p, q} {p}
q {r} {r}
r {s} φ
∗s {s} {s}

[1, Ex. 2.3.1]

2. Give a nondeterministic finite automaton to accept the following language: the set of
strings over alphabet {0, 1, . . . , 9} such that the final digit has appeared before. [1, Ex.
2.3.4a]

Page 2 of 3
3. Design an NFA to accept the set of all strings ending in abc, abd or aacd. Assume the
alphabet is {a, b, c, d}. [1, Ex. 2.4.4a]

4. Design an NFA to accept the language {abc, abd, aacd}. Assume the alphabet is {a, b, c, d}.

5. Consider the following NFA:

 a b c
→p φ {p} {q} {r}
q {p} {q} {r} φ
∗r {q} {r} φ {p}

(a) Compute the -closure of each state.


(b) Give all the strings of length three or less accepted by the automaton.
(c) Convert the automaton to a DFA. [1, Ex. 2.5.1]

6. Construct an NFA with three states to recognize the language

{w : w ends with 00}.

[2, Ex. 1.7a]

7. Prove that every NFA can be converted to an equivalent one that has a single accept
state. [2, Ex. 1.11]

References
[1] J. E. Hopcroft, R. Motwani and J. D. Ullman, “Introduction to Automata Theory, Lan-
guages, and Computation”, 3rd Edition, Pearson Education India, 2008.

[2] M. Sipser, “Introduction to the Theory of Computation”, 3rd Edition, Cengage, 2014.

Page 3 of 3

You might also like