Solutions To Homework 7: Exercise 1 (Ex 7.4.1, Page 301) - Give Algorithms To Decide The Following
Solutions To Homework 7: Exercise 1 (Ex 7.4.1, Page 301) - Give Algorithms To Decide The Following
March 7, 2015
Exercise 1 (Ex 7.4.1, page 301). Give algorithms to decide the following:
a) Is L(G) finite, for a given CFG G? Hint: Use the pumping lemma.
Exercise 2 (Ex 7.4.2, page 308). Develop linear-time algorithms for the
following questions about CFG’s:
1
(b) Initially, mark all variables A with production A → ϵ. If there is a
production A → B1 B2 . . . Bm , where all Bi ’s all nullable, then mark A as
nullable. This can be implemented in linear time (for each production of the
form A → B1 B2 . . . Bm , assign an integer denoting the number of nullable
variable on the right hand side, which is 0 initially; for each variable A, store
a list of pointers to all productions whose right hand side containing A, and
when A becomes nullable, update the corresponding counters).
Exercise 3 (Ex 8.2.2, page 335-336). Design Turing machines for the fol-
lowing languages:
b) {an bn cn : n ≥ 1}.
Proof. (a)
Exercise 4 (Ex 8.2.3, page 336). Design a Turing machine that takes as
input a number N and adds 1 to it in binary. To be precise, the tape initially
contains a $ followed by N in binary. The tape head is initially scanning
the $ in state q0 . Your TM should halt with N + 1, in binary, on its tape,
scanning the leftmost symbol of N + 1, in state qf . You may destroy the $
2
Figure 2: TM accepting {wwR : w is any string of 0’s and 1’s}
Exercises are from the book “Automata Theory, Language, and Compu-
tation”, 3rd edition, by John E. Hopcroft, Rajeev Motwani, and Jeffrey D.
Ullman, published by Addison-Wesley.