Professional Documents
Culture Documents
Models of Computation:
Automata and Formal Languages
ii
Preface
Models of Language
Generation and Recognition
iii
Preface
The knowledge that we will learn in this course has so permeated other areas of computer science (and even other disciplines)
that virtually all of it has practical application. The following page shows just a few application examples that you can easily find
in other CS text books on your bookshelf. In the near future, you will be dealing with string searching and pattern matching on
the Internet, and you will be reminded of the finite state automata and regular expressions that you will learn in this course. To
design a new programming language that can be used in a small embedded system, you would review the topics for the formal
languages. Most importantly, you would be using the ability, which you might have nurtured while studying the subject, to reason
and express precisely in dealing with the problems in your profession.
Theory is the product of abstraction, the process of conceptualization of important features that are common to a wide range of
special topics. Automata are the abstract models for computers that embody the essential features for computing. Thus it is not
surprising to see that automata theory is applicable to solving many problems that we encounter while dealing with real
computers. So it is with the formal languages as well. We will learn that programming languages, such as C++, HTML, XML,
etc., are formal languages.
While the most of the material of this book is consistent with the usual content of an introductory course for automata and
formal languages, the novelty of the book is in its unique way of presentation. In a course for automata and formal languages, it
has been traditional to study the material bottom-up. Usually it starts with the lowest level models, finite automata and regular
languages, and moves up to the higher level. The contents of this book are organized the other way around. It begins with a quick
introduction to the higher level models; the Turing machines in the topic for automata, and their languages in the topic for formal
languages. Then it moves down to the models in the lower level; context-sensitive languages (linear bounded automata), context-
free languages (pushdown automata) and regular languages (finite automata) for the language models (respective, for the
machine models). In this layout, the lower level models are presented as restricted ones in the upper level. This approach helps
the reader see more clearly the whole picture of the computational models and their relationships.
iv
Preface
Application examples
Running block
0,1/ 0 1,2 / 1 dispatch
0/1
X Y
timer run out
0 2
Ready
2/0 Blocked
wakeup
(a) Digital system: state diagram of a relay (b) Operating systems : process state transition
c
c
not (c or u) stmt
[c] u
start c
[cu] if
expr then
not (c or p) stmt
p E1
any if expr stmt
then else
stmt
[cup] S2
not(c) E2 S1
(c) Web browsing: pattern matching for “cup” (d) Compiler: constructing a parse tree
v
To help the reader fully grasp important concepts, at the end of each chapter they are brought up again under the title of
“rumination” with more examples and illustrations. The manuscript carries six appendices containing some challenging material
that is too heavy to present in the main chapters.
The book is written in the PowerPoint form, with its wealth of figures, often animated, that would help the reader understand
the topics more easily. To deliver the subject with this manuscript as a text, the instructor need not develop class presentation
material. For the convenience of class presentation, whenever a figure or a formula is needed to refer, a copy of it is presented in
the current slide instead.
Texts for a theory course under the title of automata and formal languages usually include the topics on the computational
complexity and unsolvable problems. I have not included these topics because they are too advanced to study in a course intended
for the students in the second or third year of their undergraduate computer science curriculum. I usually teach Chapters 1 through
14 in one-semester course for students in their second year. Other options are possible; for example, (a) Chapters 1 through 10,
and 14, or (b) Chapters 1 through 12 and 14. For an upper or graduate level course, the full text could be covered in depth.
Acknowledgements
We would like to thank the following people: Professor Oscar Ibarra who had taught Sam, the first author, and nurtured his
knowledge in the field, Professor Robert McNaughton who helped him to grow it to its maturity. We thank Professor Mukkai
Krishnamoorthy who reviewed the early version of the material and suggested interesting exercise problems. We also extend thanks
to all former students (of CS Departments of Rensselaer Polytechnic Institute and CE Department of Kyungpook National
University) who gave valuable criticism while taking the course with an early draft. The book is still far from perfect. Any
remaining inadequacies are the responsibility of the authors. Please send any feedback to kims351535@yahoo.co.kr
S. M. Kim
K. Y. Yoo
Kyungpook National University
Daegu, Korea
December, 2009
vi
Contents
Chapter 1 Preliminaries 1
1.1 Notation 2
Symbols, Strings, Composite symbols
Sets and set operations
1.2 Propositions and logical connectives 6
1.3 Proof techniques 10
Proof by contrapositive, Proof by cases, Proof by contradiction
Proof by example, Proof by generalization
Proof by induction, Proof by pigeonhole principle
Proof by counting, Diagonalization technique
Rumination 22
Exercises 26
vii
Contents
Chapter 4 Automata 78
4.1 Deterministic Turing machines (DTM) 80
Design example
State transition graph, State transition table, State transition function
Formal definition
4.2 DLBA (Deterministic Linear Bounded Automata) 98
Definition and Design example
4.3 DPDA (Deterministic Pushdown Automata) 100
Definition
Design example
4.4 DFA (Deterministic Finite Automata) 111
Definition
Design example
Rumination 114
Exercises 120
viii
Contents
Chapter 5 Nondeterministic Automata 124
5.1 NFA (Nondeterministic Finite Automata) 126
Definition and examples
5.2 NPDA (Nondeterministic Pushdown Automata) 132
Definition and examples
5.3 NTM (Nondeterministic Turing Machines) and
NLBA (Nondeterministic Linear Bounded Automata) 139
5.4 Nondeterministic Computing 140
Nondeterministic computing
Example
5.5 NFA and -transitions 145
-transitions in an FA
Eliminating -transitions
Rumination 154
Exercises 156
ix
Contents
x
Contents
xi
Contents
xii
Contents
Appendix
A. Pascal Syntax Flow Graph 508
B. Converting 2-way FA to 1-way FA 515
C. Computing Regular Expression for the Language Recognized by an FA 532
D. Properties of Deterministic Context-free Languages 542
E. A CFL Satisfying the Pumping Lemma for Regular Languages 564
F. CYK Algorithm for the Membership Test for context-free languages 569
References 576
Index 577
xiii