Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 434 trang
THÔNG TIN TÀI LIỆU
Cấu trúc
scan0001
Binder1
scan0001
scan0002
scan0003
scan0004
scan0005
scan0006
scan0007
scan0008
scan0009
scan0010
scan0011
scan0012
scan0013
scan0014
scan0015
scan0016
scan0017
scan0018
scan0019
scan0020
scan0021
scan0022
scan0023
scan0024
scan0025
scan0026
scan0027
scan0028
scan0029
scan0030
scan0031
scan0032
scan0033
scan0034
scan0035
scan0036
scan0037
scan0038
scan0039
scan0040
scan0041
scan0042
scan0043
scan0044
scan0045
scan0046
scan0047
scan0048
scan0049
scan0050
scan0051
scan0052
scan0053
scan0054
scan0055
scan0056
scan0057
scan0058
scan0059
scan0060
scan0061
scan0062
scan0063
scan0064
scan0065
scan0066
scan0067
scan0068
scan0069
scan0070
scan0071
scan0072
scan0073
scan0074
scan0075
scan0076
scan0077
scan0078
scan0079
scan0080
scan0081
scan0082
scan0083
scan0084
scan0085
scan0086
scan0087
scan0088
scan0089
scan0090
scan0091
scan0092
scan0093
scan0094
scan0095
scan0096
scan0097
scan0098
scan0099
scan0100
scan0101
scan0102
scan0103
scan0104
scan0105
scan0106
scan0107
scan0108
scan0109
scan0110
scan0111
scan0112
scan0113
scan0114
scan0115
scan0116
scan0117
scan0118
scan0119
scan0120
scan0121
scan0122
scan0123
scan0124
scan0125
scan0126
scan0127
scan0128
scan0129
scan0130
scan0131
scan0132
scan0133
scan0134
scan0135
scan0136
scan0137
scan0138
scan0139
scan0140
scan0141
scan0142
scan0143
scan0144
scan0145
scan0146
scan0147
scan0148
scan0149
scan0150
scan0151
scan0152
scan0153
scan0154
scan0155
scan0156
scan0157
scan0158
scan0159
scan0160
scan0161
scan0162
scan0163
scan0164
scan0165
scan0166
scan0167
scan0168
scan0169
scan0170
scan0171
scan0172
scan0173
scan0174
scan0175
scan0176
scan0177
scan0178
scan0179
scan0180
scan0181
scan0182
scan0183
scan0184
scan0185
scan0186
scan0187
scan0188
scan0189
scan0190
scan0191
scan0192
scan0193
scan0194
scan0195
scan0196
scan0197
scan0198
scan0199
scan0200
scan0201
scan0202
scan0203
scan0204
scan0205
scan0206
scan0207
scan0208
scan0209
scan0210
scan0211
scan0212
scan0213
scan0214
scan0215
scan0216
scan0217
scan0218
scan0219
scan0220
scan0221
scan0222
scan0223
scan0224
scan0225
scan0226
scan0227
scan0228
scan0229
scan0230
scan0231
scan0232
scan0233
scan0234
scan0235
scan0236
scan0237
scan0238
scan0239
scan0240
scan0241
scan0242
scan0243
scan0244
scan0245
scan0246
scan0247
scan0248
scan0249
scan0250
scan0251
scan0252
scan0253
scan0254
scan0255
scan0256
scan0257
scan0258
scan0259
scan0260
scan0261
scan0262
scan0263
scan0264
scan0265
scan0266
scan0267
scan0268
scan0269
scan0270
scan0271
scan0272
scan0273
scan0274
scan0275
scan0276
scan0277
scan0278
scan0279
scan0280
scan0281
scan0282
scan0283
scan0284
scan0285
scan0286
scan0287
scan0288
scan0289
scan0290
scan0291
scan0292
scan0293
scan0294
scan0295
scan0296
scan0297
scan0298
scan0299
scan0300
scan0301
scan0302
scan0303
scan0304
scan0305
scan0306
scan0307
scan0308
scan0309
scan0310
scan0311
scan0312
scan0313
scan0314
scan0315
scan0316
scan0317
scan0318
scan0319
scan0320
scan0321
scan0322
scan0323
scan0324
scan0325
scan0326
scan0327
scan0328
scan0329
scan0330
scan0331
scan0332
scan0333
scan0334
scan0335
scan0336
scan0337
scan0338
scan0339
scan0340
scan0341
scan0342
scan0343
scan0344
scan0345
scan0346
scan0347
scan0348
scan0349
scan0350
scan0351
scan0352
scan0353
scan0354
scan0355
scan0356
scan0357
scan0358
scan0359
scan0360
scan0361
scan0362
scan0363
scan0364
scan0365
scan0366
scan0367
scan0368
scan0369
scan0370
scan0371
scan0372
scan0373
scan0374
scan0375
scan0376
scan0377
scan0378
scan0379
scan0380
scan0381
scan0382
scan0383
scan0384
scan0385
scan0386
scan0387
scan0388
scan0389
scan0390
scan0391
scan0392
scan0393
scan0394
scan0395
scan0396
scan0397
scan0398
scan0399
scan0400
scan0401
scan0402
scan0403
scan0404
scan0405
scan0406
scan0407
scan0408
scan0409
scan0410
scan0411
scan0412
scan0413
scan0414
scan0415
scan0416
scan0417
scan0418
scan0419
scan0420
scan0421
scan0422
scan0423
scan0424
scan0425
scan0426
scan0427
scan0428
scan0429
scan0430
scan0431
scan0432
scan0002
Nội dung
http://engineeringbooks.net THEORY OF COMPUTER SCIENCE Automata, Languages and Computation THIRD EDITION K.l.P MISHRA Formerly Professor Department of Electrical and Electronics Engineering and Principal/ Regional Engineering College Tiruchirapal/i N CHANDRASEKARAN Professor Department of Mathematics St Joseph/s College Tiruchirapalli Prentice'Hall of India [P[?lmGJD@ LsOWJov8d] New Delhi - 110 '001 2008 http://engineeringbooks.net Contents Preface ix Notations Xl PROPOSITIONS AND PREDICATES 1.1 Propositions (or Statements) 1.1.1 Connectives (Propositional Connectives or Logical Connectives) 1.1.2 Well-formed Formulas 1.1.3 Truth Table for a Well-formed Formula 1.1.4 Equivalence of Well-formed Formulas 1.1.5 Logical Identities 1.2 Normal Forms of Well-formed Formulas 11 1.2.1 Construction to Obtain a Disjunctive Normal Form of a Given Formula II 1.2.2 Construction to Obtain the Principal Disjunctive Normal Form of a Given Formula 1.3 Rules of Inference for Propositional Calculus (Statement Calculus) 15 1.4 Predicate Calculus 19 1.4.1 Predicates 19 1.4.2 Well-formed Formulas of Predicate Calculus 1.5 Rules of Inference for Predicate Calculus 23 1.6 Supplementary Examples 26 Se(f-Test Exercises 1-35 12 21 31 32 iii http://engineeringbooks.net iv J;J Contents MATHEMATICAL PRELIMINARIES 2.1 Sets, Relations and Functions 36 2.1.1 Sets and Subsets 36 37 2.1.2 Sets with One Binary Operation 2.1.3 Sets with Two Binary Operations 39 2.1.4 Relations 40 43 2.1.5 Closure of Relations 2.1.6 Functions 45 2.2 Graphs and Trees 47 2.2.1 Graphs 47 2.2.2 Trees 49 2.3 Strings and Their Properties 54 2.3.1 Operations on Strings 54 2.3.2 Terminal and Nonterrninal Symbols 56 2.4 Principle of Induction 57 2.4.1 Method of Proof by Induction 57 58 2.4.2 Modified Method of Induction 2.4.3 Simultaneous Induction 60 2.5 Proof by Contradiction 61 2.6 Supplementary Examples 62 Self-Test Exercises 66 67 THE THEORY OF AUTOMATA 3.1 Definition of an Automaton 7] 3.2 Description of a Finite Automaton 73 3.3 Transition Systems 74 3.4 Propeliies of Transition Functions 75 3.5 Acceptability of a String by a Finite Automaton 77 3.6 Nondeterministic Finite State Machines 78 3.7 The Equivalence of DFA and NDFA 80 3.8 Mealy and Moore Models 84 3.8.1 Finite Automata with Outputs 84 3.8.2 Procedure for Transforming a Mealy Machine into a Moore Machine 85 3.8.3 Procedure for Transforming a Moore Machine 87 into a Mealy Machine 3.9 Minimization of Finite Automata 91 3.9.1 Construction of Minimum Automaton 92 97 3.10 Supplementary Examples Self-Test Exercises 36-70 71-106 103 ] 04 http://engineeringbooks.net Contents !O!l v FORMAL 4.1 Basic 4.1.1 4.1.2 LANGUAGES 107 Definitions and Examples Definition of a Grammar 109 Derivations and the Language Generated by a 110 Grammar 120 4.2 Chomsky Classification of Languages 4.3 Languages and Their Relation 123 124 4.4 Recursive and Recursively Enumerable Sets 126 4.5 Operations on Languages 4.6 Languages and Automata 128 129 4.7 Supplementary Examples Self-Test 132 Exercises 134 107-135 REGULAR SETS A~TJ) REGULAR GRAMMARS 136-179 5.1 Regular Expressions 136 5.1.1 Identities for Regular Expressions 138 5.2 Finite Automata and Regular Expressions 140 140 5.2.1 Transition System Containing A-moves 5.2.2 NDFAs with A-moves and Regular Expressions 142 5.2.3 Conversion of Nondeterministic Systems to Deterministic Systems 146 5.2.4 Algebraic Method Using Arden's Theorem 148 5.2.5 Construction of Finite Automata Equivalent to a Regular Expression 153 5.2.6 Equivalence of Two Finite Automata 157 160 5.2.7 Equivalence of Two Regular Expressions 5.3 Pumping Lemma for Regular Sets 162 5.4 Application of Pumping Lemma 163 5.5 Closure Properties of Regular Sets 165 5.6 Regular Sets and Regular Grammars 167 5.6.1 Construction of a Regular Grammar Generating T(M) for a Given DFA M 168 5.6.2 Construction of a Transition System M Accepting L(G) for a Given Regular Grammar G 169 5.7 Supplementary Examples 170 Self- Test 175 Exercises 176 CONTEXT·FREE LANGUAGES 6.1 Context-free Languages and Derivation Trees 6.1.1 Derivation Trees 181 6.2 Ambiguity in Context-free Grammars 188 18G-226 180 http://engineeringbooks.net ~ vi ~ Contents 189 Simplification of Context-free Grammars 190 6.3.1 Construction of Reduced Grammars 6.3.2 Elimination of Null Productions 196 199 6.3.3 Elimination of Unit Productions 201 6.4 Normal Forms for Context-free Grammars 6.4.1 Chomsky Normal Form 201 6.4.2 Greibach Normal Form 206 213 6.5 Pumping Lemma for Context-free Languages 217 6.6 Decision Algorithms for Context-free Languages 6.7 Supplementary Examples 218 Self-Test 223 Exercises 224 6.3 PUSHDOWN AUTOMATA 7.1 Basic Definitions 227 7.2 Acceptance by pda 233 7.3 Pushdown Automata and Context-free Languages 7.4 Parsing and Pushdown Automata 251 7.4.1 Top-down Parsing 252 7.4.2 Top-down Parsing Using Deterministic pda's 7.4.3 Bottom-up Parsing 258 7.5 Supplementary Examples 260 Sell Test 264 Exercises 265 LR(k) GRAMMARS 267 8.1 LR(k) Grammars 8.2 Properties of LR(k) Grammars 8.3 Closure Properties of Languages 8.4 Supplementary Examples 272 Self-Test 273 Erercises 274 227-266 240 256 267-276 270 272 TURING MACHINES AND LINEAR BOUNDED AUTOMATA 9.1 Turing Machine Model 278 9.2 Representation of Turing Machines 279 9.2.1 Representation by Instantaneous Descriptions 280 9.2.2 Representation by Transition Table 281 9.2.3 Representation by Transition Diagram 9.3 Language Acceptability by Turing Machines 283 284 9.4 Design of Turing Machines 9.5 Description of Turing Machines 289 277-308 279 http://engineeringbooks.net Contents Techniques for TM Construction 289 9.6.1 Turing Machine with Stationary Head 289 290 9.6.2 Storage in the State 9.6.3 Multiple Track Turing Machine 290 9.6.4 Subroutines 290 9.7 Variants of Turing Machines 292 9.7.1 Multitape Turing Machines 292 9.7.2 Nondeterministic Turing Machines 295 9.8 The Model of Linear Bounded Automaton 297 9.8.1 Relation Between LBA and Context-sensitive Languages 299 9.9 Turing Machines and Type Grammars 299 9.9.1 Construction of a Grammar Corresponding to TM 9.10 Linear Bounded Automata and Languages 301 9.11 Supplementary Examples 303 Self-Test 307 Exercises 308 ~ vii 9.6 10 DECIDABILITY AJ\i'D RECURSIVELY El\TU1\fERABLE LANGUAGES 10.1 The Definition of an Algorithm 309 10.2 Decidability 310 10.3 Decidable Languages 311 10.4 Undecidable Languages 313 10.5 Halting Problem of Turing Machine 314 10.6 The Post Correspondence Problem 315 10.7 Supplementary Examples 317 Self-Test 319 Exercises 319 299 309-321 322-345 11 COMPUTABILITY 11.1 Introduction and Basic Concepts 322 11.2 Primitive Recursive Functions 323 11.2.1 Initial Functions 323 325 11.2.2 Primitive Recursive Functions Over N 11.2.3 Primitive Recursive Functions Over {a b} 327 11.3 Recursive Functions 329 332 11.4 Partial Recursive Functions and Turing Machines 11.4.1 Computability 332 333 11.4.2 A Turing Model for Computation 11.4.3 Turing-computable Functions 333 11.4.4 Construction of the Turing Machine That Can Compute the Zero Function Z 334 11.4.5 Construction of the TUling Machine for ComputingThe Successor Function 335 http://engineeringbooks.net viii J;;;l Contents 11.4.6 Construction of the Turing Machine 336 the Projection Vi" 11.4.7 Construction of the Turing Machine Perform Composition 338 11.4.8 Construction of the Turing Machine Perform Recursion 339 11.4.9 Construction of the Turing Machine Minimization 340 11.5 Supplementary Examples 340 Self-Test 342 Exercises 343 for Computing That Can That Can That Can Perform 12 COMPLEXITY 12.1 Growth Rate of Functions 346 12.2 The Classes P and NP 349 12.3 Polynomial Time Reduction and NP-completeness 352 12.4 Importance of NP-complete Problems 353 12.5 SAT is NP-complete 12.5.1 Boolean Expressions 353 12.5.2 Coding a Boolean Expression 353 12.5.3 Cook's Theorem 354 359 12.6 Other NP-complete Problems 360 12.7 Use of NP-completeness 12.8 Quantum Computation 360 12.8.1 Quantum Computers 361 12.8.2 Church-Turing Thesis 362 363 12.8.3 Power of Quantum Computation 12.8.4 Conclusion 364 12.9 Supplementary Examples 365 Self-Test Exercises 346-371 351 369 370 Answers to Self-Tests 373-374 Solutions (or Hints) to Chapter-end Exercises 375-415 Further Reading 417-418 Index 419-422 http://engineeringbooks.net Preface The enlarged third edition of Thea/}' of Computer Science is the result of the enthusiastic reception given to earlier editions of this book and the feedback received from the students and teachers who used the second edition for several years, The new edition deals with all aspects of theoretical computer science, namely automata, formal languages, computability and complexity, Very few books combine all these theories and give/adequate examples This book provides numerous examples that illustrate the basic concepts It is profusely illustrated with diagrams While dealing with theorems and algorithms, the emphasis is on constructions Each construction is immediately followed by an example and only then the formal proof is given so that the student can master the technique involved in the construction before taking up the formal proof The key feature of the book that sets it apart from other books is the provision of detailed solutions (at the end of the book) to chapter-end exercises The chapter on Propositions and Predicates (Chapter 10 of the second edition) is now the first chapter in the new edition The changes in other chapters have been made without affecting the structure of the second edition The chapter on Turing machines (Chapter of the second edition) has undergone major changes A novel feature of the third edition is the addition of objective type questions in each chapter under the heading Self-Test This provides an opportunity to the student to test whether he has fully grasped the fundamental concepts Besides, a total number of 83 additional solved examples have been added as Supplementary Examples which enhance the variety of problems dealt with in the book ix http://engineeringbooks.net x );! Preface The sections on pigeonhole principle and the principle of induction (both in Chapter 2) have been expanded In Chapter 5, a rigorous proof of Kleene's theorem has been included The chapter on LR(k) grammars remains the same Chapter as in the second edition Chapter focuses on the treatment of Turing machines (TMs) A new section on high-level description of TM has been added and this is used in later examples and proofs Some techniques for the construction of TMs have been added in Section 9.6 The multitape Turing machine and the nondeterministic Turing machine are discussed in Section 9.7 A new chapter (Chapter 10) on decidability and recursively enumerable languages is included in this third edition In the previous edition only a sketchy introduction to these concepts was given Some examples of recursively enumerable languages are given in Section 10.3 and undecidable languages are discussed in Section lOA The halting problem of TM is discussed in Section 10.5 Chapter 11 on computability is Chapter of the previous edition without changes Chapter 12 is a new chapter on complexity theory and NP-complete problems Cook's theorem is proved in detail A section on Quantum Computation is added as the last section in this chapter Although this topic does not fall under the purview of theoretical computer science, this section is added with a view to indicating how the success of Quantum Computers will lead to dramatic changes in complexity theory in the future The book fulfils the curriculum needs of undergraduate and postgraduate students of computer science and engineering as well as those of MCA courses Though designed for a one-year course, the book can be used as a onesemester text by a judicious choice of the topics presented Special thanks go to all the teachers and students who patronized this book over the years and offered helpful suggestions that have led to this new edition In particular, the critical comments of Prof M Umaparvathi, Professor of Mathematics, Seethalakshmi College, Tiruchirapalli are gratefully acknowledged Finally the receipt of suggestions, comments and error reports for further improvement of the book would be welcomed and duly acknowledged K.L.P Mishra N Chandrasekran http://engineeringbooks.net 408 Q Solutions (or Hints) to Chapter-end Exercises derivations of 01 2k + 12 and 01 2k+ 32 given by: S ~ 01 kAl k2 ~ 01 2k+ 12 R where a = 01\ f3 R = a, W = af3w (A8.I) = 1k2 S ~ 01 k+ 1A1 k + 12 ~ OI 2k + :::} a'{3'w' R (A8.2) R where a' = 01 k+l, f3' = a, w' = l'k+12 As the strings formed by the first 2k + symbols (note laf31 + k = 2k + 1) of af3w and a'{3'w' are the same a = at, i.e Ol k = 01 k+ 1, which is a contradiction Thus the given grammar is not LR(k) for any k 8.3 The given grammar is ambiguous and hence is not LR(k) for any k For example, there are two derivation trees for abo 8.4 As a"b"e" appears in both the sets, it admits two different derivation trees So the set cannot be generated by an unambiguous grammar Chapter 9.2 The set of quintuples representing the TM consists of q 1bILq2, qIOORql, q:bbRq3' q:OOLq2, q211Lq2, q30bR% q3 1bRqs· q4 bOR qs, q400Rq4, q4IIRq4 QSbOLq2' 9.3 The computation for the first symbol is qjllbll Afterwards it halts f-c- bq2bIl 9.4 The computation sequence for the substring 12 of 1213 is q j I213 f-c- bq2213 f-c- bbq3 13 As 8(q3' 1) is not defined, the TM halts For 2133 and 312 the TM does not start 9.6 Modify the construction given in Example 9.7 9.8 We have the following steps for processing the even-length palindromes: (a) The Turing machine M scans the first symbol of the input tape (0 or 1), erases it and changes state (qj or q2)' (b) M scans the remaining part without changing the tape symbol until it encounters b (c) The RJW head moves to the left If the rightmost symbol tallies with the leftmost symbol (which can be erased but remembered), the rightmost symbol is erased Otherwise M halts (d) The R/W head moves to the left until b is encountered Steps (a), (b) (c), (d) are repeated after changing the states suitably The transition table is defined by Table A9.1 Solutions (or Hints) to Chapter-end Exercises TABLE A9.1 409 Transition Table for Exercise 9.8 Present state Input symbol !;t bRqj ORq1 ORq1 bLq5 qa q1 q2 q3 q4 q5 q6 OLq5 OLq6 b bRq2 1Rq1 1Rq2 bRq7 bLq3 bLq4 bLq6 Lq5 1Lq6 bRqa bRqa ® 9.9 We have three states qQ, qj, qj, where qQ is the initial state used to remember that even number of l's have been encountered so far qj is used to remember that odd number of l's have been encountered so far qr is the final state The transition table is defined by Table A9.2 TABLE A9.2 Present state Transition Table for Exercise 9.9 o b 9.10 The construction given in Example 9.7 can be modified As the number of occurrences of c is independent of that of a or b, after scanning the rightmost c, the RJW head can move to the left and erase c 9.11 Assume that the input tape has 011l 1O" where m '- n is required We have the following steps: (a) The leftmost is replaced by b and the RJW head moves to the right (b) The RIW head replaces the first after by and moves to the left On reaching the blank at the left end the cycle is repeated (c) Once the 0' s to the left of l' s are exhausted, M replaces all 0' sand l' s by b' s a '- b is the number of 0' s left over in the input tape and equal to O (d) Once the O's to the right of l's are exhausted, nO's have been changed to l's and n + of m O's have been changed to b M replaces l's (there are n + II's) by one and n b's The number of O's remaining gives the values of a '- b The transition table is defined by Table A9.3 410 !!!! Solutions (or Hints) to Chapter-end Exercises TABLE A9.3 Transition Table for Exercise 9.11 Present state Input symbol qo q, q2 q3 q4 Qs b bRq, ORq, 1Lq3 OLQ3 OLq4 bRQs bRqs 1Rq2 1Rq2 1Lq3 bLq4 bRQs bLq4 bRqo ORQ6 bRQ6 ® Chapter 10.2 10 (B, w) is an input to M Convert B to an equivalent DFA A Run the Turing machine M j for AOFA on input (A, w) If M j accepts, M accepts; otherwise M rejects 10.3 Construct a TM M as follows: (A) is an input to M Mark the initial state of A (qo marked as q'6, a new symbol) Repeat until no new states are marked: a new state is marked if there is a transition from a state already marked to the new state If a final state is marked, M accepts (A); otherwise it rejects 10.4 Let L = (T(A l ) - T(A 2)) Apply E OFA to (A') U (T(A 2) - T(A l )) L is regular and L = T(A') 10.8 Use Examples 10.4 and 10.5 10.9 A TM is regarding a given Turing machine accepting an input, that is, reaching an accepting state after scanning wand halting HALTTM is regarding a given TM halting on an input (or M need not accept w in this case) 10.10 Represent a number between and as Qj Q • where Qj, Q2, ••• are binary digits Assume the set to be a sequence, apply diagonalization process and get a contradiction 10.11 When a problem is undecidable, we can modify or take a particular case of the problem and try for algorithms Studying undecidable problems may kindle an imagination to get better ideas on computation 10.12 Suppose the problem is solvable Then there is an algorithm to decide whether a given terminal string w is in L Let M be a TM Then there is a grammar G such that L( G) is the same as the set accepted by M Then w E L(G) if and only if M halts on w This means that the halting problem of TM is solvable, which is a contradiction Hence the recursiveness of a type grammar is unsolvable Solutions (or Hints) to Chapter-end Exercises Q 411 10.14 Suppose there exists a Turing Machine Mover {O, l} and a state qlll such that the problem of determining whether or not M will enter qm is unsolvable Define a new Turing machine M' which simulates M and has the additional transition given by 6(qm' A) = (qm' 1, R) Then M enters qlll when it starts with a given tape configuration if and only if M' prints when it starts with a given tape configuration Hence the given problem is unsolvable 10.17 According to Church's thesis we can construct a Turing Machine which can execute any given algorithm Hence the given statement is false (Of course, the Church's thesis is not proved But there is enough evidence to justify its acceptance.) 10.18 Let L = {a} Let X, ak; , I• -_ 1, 2, X2, , xn) and Y = (YI, Y2, , Yn), where Ii ] T n an d )j} a·, , , , n hen ()Il( Xl X2 )IZ .(xjlJ = (Yli 1(Y2)k Z (Y,ilJ • Both are equal to a Lkil ; Hence PCP is solvable when I L I = 10.20 Xl for x = (x], , = 01, Y1 = OIl, X2 = 1, Y2 = 10, x3 = 1, Y3 = Hence IXi I < IYi I i = 1, 2, So XilXi2 xi :;t YiIYiz Yi for no choice of i's m m I xilXiz xl m < 1Yi1Yiz Yi m I· Hence the PCP with the given Note: lists has no solution 10.21 = 0, Y1 = 10, X2 = 110, Y2 = 000, X3 = 001, Y3 = 10 Here no pair or (x3' Y3) has common nonempty initial substring So XilXiz xim :;t YilYiz Yi m for no choice of i/s Hence the PCP with the given lists has solution Xl (Xlo YI), (x2' Y2) 10.22 As = Y1, Xl the PCP with the given lists has a solution 10.23 In this problem, Xl = 1, X2 = 10, X3 = 1011, Y1 = 111, Y2 = 0, Y3 = 10 Then, XJX1X1X2 = Y3Y1Y1Y2 = 101111110 Hence the PCP with the given lists has a solution Repeating the sequence 3, 1, 1, 2, we can get more solutions 10.24 Both (a) and (b) are possible One of them is possible by Church's thesis Find out which one? Chapter 11 11.1 (a) The function is defined for all natural numbers divisible by (b) x =2 (c) x ;:: (d) all natural numbers (e) all natural numbers 11.2 (a) X(Oj(O) = 1, X(Oj(x + 1) -'- X(Ojsgn(p(x») (b) f(x + 1) = x + 2x + So, f(x + 1) = f(x) + S(S(Z(x»)) * ui(x) + S(Z(x» 412 J!!1, Solutions (or Hints) to Chapter-end Exercises Hence f is obtained by recursion and addition of primitive recursive functions (c) l(x, y) =y + (x -'- y) (d) Define parity function P,.(y) by = P r(3) = = P, is primitive recursive since Pr(o) = 0, Pr(x + 1) = x{o}(Ul(x), Pr(x)) Define f by 1(0) = 0, f(x + 1) = f(x) + P,.(x) Pr(o) = P,.(2) = = 0, Pll) (e) sgn(O) = Z(O) , sgn(x + 1) = s(z(ul (x, sgn (x)))) (f) L(x, y) = sgn(x -'- y) (g) E(x, y) = X{Oj«x -'- y) + (y -'- x)) All the functions (a)-(g) are obtained by applying composition and recursion to known primitive functions and hence primitive recursive functions 11.3 A(I, y) = A(1 + 0, Y - + 1) = A(O, A(1, y - 1)) using (11.10) of Example 11.11 Using (11.8), we get A(1, y) = + A(I, Y - 1) Repeating the argument, we have A(I, y) =y - + A(I, 1) =y + (By Example 11.12, A(I, 1) = 3) This result is used in evaluating A(3, 1) A(2, 3) = A(l + 1, + 1) = A(I, A(2, 2)) = A(1, 7) using y + 2, we get A(2, 3) + Example 11.12 Using A(I, y) Then using (11.10), A(3, 1) A(2 + 1, + 1) A(2, A(3, 0») By Example 11.12, A(2, 1) Also, A(3, 0) A(2, 1) by (11.9) A(l + 1, + 1) A(I, A(2, 4» Since Hence A(3, 1) A(2, 5) A(l, y) = Y + 2, A(3, 1) = + A(2, 4) Applying (11.10), we have A(2, 4) A(I, A(2, 3)) + A(2, 3) + 11 = = = = = ° = = = = = = = Hence, A(3, 1) = + 11 = 13 A(3, 2) = A(2, A(3, 1)) = A(2, 13) = A(I, A(2, 12)) = + A(2, = + A(l, A(I, 11) = + A(1, 13) = + + 13 = 17 = = 12) To evaluate A(3, 3), we prove A(2, y + 1) = 2y + A(2, 1) Now, = A(1, A(2, y) = + A(2, y) Repeating this argument, A(2, y + 1) = 2y + A(2, 1) Now, A(3, 3) = A(2 + 1, + 1) = A(2, A(3, 2» = A(2, 17) = 2(16) A(2, 1) = 32 + = 37 A(2, y + 1) = A(l + 1, y + 1) + Solutions (or Hints) to Chapter-end Exercises = ~ 413 11.4 (b) It is clear that rex, 0) O Also, rex, y) increases by when y is increased by and rex, y) when y x Using these observations we see that rex, y + 1) S(r (x,y)) * sgn(x -'- S(r (x, y))) Hence rex, y) is defined by = rex, 0) = = =0 rex, y + 1) = S(r(x, y)) * sgn(x -'- S(r(x, y))) 11.5 I(x) is the smallest value of y for which (y + 1)2 > x Therefore, fix) uyCX[O}((y + 1)2 -'- x)), I is partial recursive since it is obtained = from primitive recursive functions by application of minimization 11.8 The constant function I(x) = is primitive recursive for 1(0) = and fix + 1) Ul(x, fix)) Now XAc, XAnB and XA u B are recursive for = -'- XA' XAnB = XA * XB and XAuB = XA + XB -'- XAnB (Addition and proper subtraction are primitive recursive functions and the given functions are obtained from recursive functions using composition.) XAc =1 11.9 Let E denote the set of all even numbers XE(O) = 0, XECn + 1) = -'- sgn( U}(n, XE(n)) The sign function and proper subtraction function are primitive recursive Thus E is obtained from primitive recursive functions using recursion Hence XE is primitive recursive and hence recursive To prove the other part use Exercise 11.8 11.11 Define I by flO) = k, fin + 1) = U}(n, j(n)) Hence I is primitive recurSIve 11.12 = X{ad + X[a2} + + X{a ll }' As X{ad is primitive recursive (Refer to Exercise 11.2(a)) and the sum of primitive recursive functions is primitive recursive, X{ar, a2, , all} is primitive recursive X{{lj.a2'" all } 11.13 Represent x and y in tally notation Using Example 9.6 we can compute concatenation of strings representing x and y which is precisely x + y in tally notation 11.14 Let M in the Post notation have {qj, q2, , qll} and {at> a2, , am} as Q and L respectively Let Q' = {qj, , qll' qll+j, , q21l}, where qll+l , q211 are new states Let a quadruple of the form qiajRqk induce the quintuple qiapkRqk' Let a quadruple of the form qia/-LJk induce the quintuple q;apjLqk' Finally, let qiapkq, induce qiapkRqll+i' We introduce quintuples qll+iafltLqi for i = 1, 2, , nand t = 1, 2, 3, , m The required TM has Q' as the set of states and the set of quintuples represent 414 j;\ Solutions (or Hints) to Chapter-end Exercises 11.15 qo1ll1xlby ~ llllqoXlby ~ llllqlxby As b lies between Z(4) (given by b) = Xl and y, 11.16 In Section 11.4.5 we obtained q01xlby ~ qs1xbbly Similarly, qoll1xlby ~ qs1llxlb1y ~ 1qollxlbly Proceeding further, 1qollxlb1y ~ 1qsllxlblly ~ llqolx l blly f-"'- lllqc;Xllllly (as in Section 11.4.5) Hence S(3) = 11.18 Represent the argument x in tally notation j(x) = S(S(x» Using the construction given in Section 11.4.7, we can construct a TM which gives the value S(S(x» 11.19 f(x]> = S(S(U?(x]> X2) X2»)' Use the construction in Section 11.4.7 11.20 Represent (Xl> X2) by P 1bl'2 By taking the input as $1' Ib1'2($ is representing the left-end) and suitably modifying the TM given in Example 9.6, we get the value of Xl + X2 to the right of $ Chapter 12 k 12.1 Denote j(n) I = 1=0 L aini and g(n) = /=0 L bini, where k integers Assume k :2 aj, bi' are positive < t Then fen) + g(n) = L 1=0 i (ai + bJn , where b i = for i > l f(n) + g(n) is a polynomial of degree k Hence j(n)g(n) = O(nk+/) 12.2 As n dominates n log nand n 10g n dominates n 2, the growth rate of hen) > growth rate of g(n) Note f(n) g(n) 0(n 2) = Jl 12.3 As L i 1=0 = n(n + 1)/2, II L 1=0 = P = n(n + 1)(211 + 1)/6 and 11 L 1=0 P = (n(n + 1)12)2, the answers for (i) and (ii) are 0(n ) and O(n\ (iii) a(1 - r")/l - r n O(l'lr) = 0(1'-1) (iv) '2 [2a + (n-1)d] = 0(n 2) = 12.4 As log2 n, 10g3 n, loge n, differ by a constant factor, j(n) = O(r/ log n) 12.5 gcd = 12.6 The principal disjunctive normal form of the boolean expression has terms (refer to Example 1.13) P ;\ Q ;\ R is one such term So (T, T, T) satisfies the given expression Similar assignments for the other four terms 12.7 No 12.8 (T T, F, F) makes the given expression satisfiable 12.9 Only if: Take an NP-complete problem L Then r is in CO-NP = NP Solutions (or Hints) to Chapter-end Exercises J!O! 415 if: Let P be IVP-complete and P E NP Let L be any language in NP We get a polynomial reduction ¢ of L to P and hence a polynomial reduction If! of [ to p We prove NP c CO-NP Combine If! and nondeterministic polynomial-time algorithms for p to get a nondeterministic polynomial-time algorithm for [ So [ E NP or L E CO-NP This proves NP c CO-NP The other inclusion is similar Further Reading Chandrasekaran, N., Automata and Computers, Proceedings of the KMA National Seminar on Discrete Mathematics and Applications, St Thomas College, Kozhencherry, January, 9-11, 2003 Davis, M.D and E.J Weyuker, Computability, Complexity and Languages Fundamentals of Theoretical Computer Science, Academic Press, New York, 1983 Deo, N., Graph Theory ,vith Applications to Engineering and Computer Science, Prentice-Hall of India, New Delhi, 2001 Ginsburg, S., The Mathematical Theory of Context-Free Languages, McGraw-HilL New York 1966 Glorioso R.M., Engineering Cybernetics, Prentice-Hall Englewood Cliffs, New Jersey 1975 Gries, D., The Science of Programming, Narosa Publishing House, New Delhi, 1981 Hanison, M.A., Introduction to Fonnal Language Them}', Addison-Wesley, Reading (Mass.) 1978 Hein J.L., Discrete Structures, Logic and Computability, Narosa Publishing House, New Delhi, 2004 Hopcroft J.E and J.D Ullman, Fa nl1al Languages and Their Relation to Automata, Addison-Welsey, Reading (Mass.) 1969 Hopcroft J.E., and J.D Ullman, Introduction to Automata Theory, Languages and Computation, Narosa Publishing House New Delhi, 1987 Hopcroft J.E T Motwani and J.D Ullman, Introduction to Automata Theory, Languages and Computation, Pearson Education, Asia, 2002 417 418 ~ Further Reading Kain, R.Y., Automata Theon: Machines and Languages, McGraw-HilI, New York 1972 Kohavi, ZVI Switching and Finite Automata Theory', Tata McGraw-Hil! New Delhi, 1986 Korfhage, RR Discrete New York, 1984 Computational Structures, Academic Press Krishnamurthy, E.V., Introductory Theory of Computer Science, Affiliated East-West Press New Delhi 1984 Levy, L.S Discrete Structures of" Computer Science, Wiley Eastern, New Delhi 1988 Lewis, H.R and c.L Papadimitrou, Elements of" the Theory of Computation, 2nd ed., Prentice-Hall of India, New Delhi 2003 Linz P An Introduction to Formal Languages and Automata, Narosa Publishing House New Delhi 1997 Mandelson, E., Introduction to Mathematical Logic, D Van Nostrand, New York, 1964 Manna, Z Mathematical Theory of Computation, McGraw-Hill Kogakusha, Tokyo 1974 Martin, J.H Introduction to Languages and the Theory of Computation, McGraw-Hill International Edition New York 1991 Minsky, M., Computation: Finite and Int"inite Machines, Prentice-Hall, Englewood Cliffs, New Jersey, 1967 Nelson, R.J., Introduction to Automata, Wiley, New York, 1968 Preparata, F.P and RT Yeh, Introduction Addison-Wesley, Reading (Mass.), 1973 to Discrete Structures, Rani Siromoney Fonnal Languages and Automata, The Chiristian Literature Society, Madras, 1979 Revesz G.E., Introduction to Fomwl Languages, McGraw-HilL New York, 1986 Sahni, D.F and D.F McAllister Discrete Mathematics in Computer Science, Prentice-Hall, Englewood Cliffs New Jersey 1977 Sipser, M., Introduction to the Theory of Computation, Brooks/Cole, Thomson Learning, London 2003 Tremblay J.P and R Monohar Discrete Mathematical Structures with Applications to Computer Science, McGraw-Hill, New York, 1975 Ullman J.D., Fundamental Concepts of Addison-Wesley, Reading (Mass.), 1976 Programming Systems, Index Abelian group 38 Acceptance by finite automaton 77 by NDFA, 79 by pda by final state, 233-240 by pda by nun store, 234-240 by Turing machine, 284 Accepting state (see Final state) Ackermann's function, 330 Algebraic system, 39 Algorith.'Il, 124, 309, 310 Alphabet 54 Ambiguous grammar, 188 Ancestor of a vertex, 51 Arden's theorem 139 Associativity 38 A-tree 183 Automaton 71 72 minimization of 91-97 Bijection, 45 Binary operation, 38 Binary trees 51 Boolean expressions, 353 Bottom-up parsing, 258 Chain production (see Unit production) Characteristic function, 344 Chomsky classification 220 Chomsky normal form (see Normal form) Church-Turing thesis, 362 Circuit 49 Closure, 37 properties, 126-128, 165-167, 272 of relations, 43 Commutativity, 38, 39 Comparison method, 152 Complexity, 346-371 Composition of functions 324 Concatenation, 54 Congruence relation, 41 Conjunction (AND), Conjunctive normal form, 14 Connectives, 2-6 Construction of reduced grammar, 190-196 Context-free grammar (language), 122, 180-218 decision algorithms for, 217 normal forms for, 201-213 and pda, 240-251 simplification of, 189-201 Context-sensitive grammar (language), 120, 299 Contradiction, Cook's theorem 354 CSAT 359 Decidability 310 Decidable languages, 311 419 420 ~ Index Decision algorithms (see Context-free grammar) Derivation, 110, 111 leftmost, 187 rightmost, 187 Derivation tree (parse tree), 181 184 definition of, 181 subtree of, 182 yield of, 182 Descendant, 51 Deterministic finite automaton, 73 pda, 236 Directed graph (or digraph), 47 Dirichlet drawer principle, 46 Disjunction (OR), Disjunctive nonnal fonn, 11 Distributivity, 39 Elementary product, 11 Equivalence class, 42 of DFA and NDFA, 80 84 of finite automata, 157, 158 of regular expressions, 160 relation, 41 of states, 91 of well-fonned fonnulas, Euclidean algorithm, 349 Fibonacci numbers, 69 Field, 39 Final state, 73, 74, 77 Finite automaton deterrrtinistic, 73 minimization of, 91-97 nondeterministic, 78 and regular expression, 153 Function (or map), 45 by minimization, 330 partial, 322 by recursion, 328 total, 322 GOdel, Kurt, 332 Grammar, 109 monotonic, 121 self-embedding, 226 Graph,47 connected, 49 representation, 47 Greibach nonnal fonn (see Nonnal fonn) Group, 38 Growth rate of functions, 346 Halting problem of Turing machine, 314-315 Hamiltonian circuit problem, 359 Handle production, 268 Hierarchy of languages, 120 122 ID (Instantaneous description) of pushdown automaton, 229 of Turing machine, 279 Identities logical, 10 for regular expressions, 138 Identity element, 38, 55 If and only if, Implication (IF,,,THEN,,,), Inclusion relation, 123 Initial function, 323 Induction, 57, 58, 60 Initial state, 73-74, 78, 228, 278 Internal vertex, 50 Inverse, 38 Kleene's theorem, 142 A-move, 140 elimination of, 141 Language(s) and automaton, 128 classification of, 120 generated by a grammar, 110 Leaf of a tree, 50 Length of path, 51 of string, 55 Levi's theorem, 56 Linear bounded automaton (LBA), 297-299, 301-303 and languages, 299-301 Logical connectives (see Connectives) LR(k) graJlh'TIar, 267 Index Map, 45, 46 bijection (one-to-one correspondence), 45 one-to-one (injective), 45 onto (surjective), 45 Maxterm 14 Mealy machine, 84 transformation into Moore machine, 85-87 Minimization of automata 91-97 Minterm, 12 Modus ponens, 16 Modus tollens, 16 Monoid 38 Moore machine, 84 transformation into Mealy machine, 8789 "\love relation in pda, 230 in Turing machine, 280 '{AND, 33 Negation (NOT), Nondeterministic finite automaton, 78 conversion to DFA, 80 Nondeterministic Turing machine, 295-297 NOR 33 Normal form Chomsky, 201-203 Greibach 206 213 of well-formed formulas, II NP-complete problem, 352 importance of, 352 Null productions, 196 elimination of 196 199 One-to-oniC correspondence (see Bijection),45 Operations on languages 126 128 Ordered directed tree 50 Palindrome 55, 113 Parse tree (see Derivation tree) Parsing and pda, 251-260 Letial recursive function 330 and Turing machine 332-340 Partition, 37 l;i 421 Path,48 acceptance by, 231-240 pda, 230 Phrase structure grammar (see Grammar) Pigeonhole principle, 46 Post correspondence problem (PCP), 315-317 Power set 37 Predecessor, 48 Predicate 19 Prefix of a string, 55 Primitive recursive function, 323-329 Principal conjunctive normal form, 15 construction to obtain, 15 Principle of induction, 57 Production (or production rule), 109 Proof by contradiction, 61 by induction, 57 by modified method, 58 by simultaneous induction, 60 Proposition (or Statement), I Propositional variable, Pumping lemma for context-free languages and applications, 213, 216 for regular sets and applications, 162-163 Push-down automaton, 227-251, 254 and context-free languages, 240-251 Quantum computation, 360 Quantum computers, 361 Quantum bit (qubiO, 361 Quantifier existential, 20 universal, 20 also Recursion, 37 Recursive definition of a set, 37 Recursive function, 329 Recursive set, 124 Recursively enumerable set, 124, 310 Reduction technique, 351 Reflexive-transitive closure, 43 Regular expressions, 136 finite automata and, 140 identities for 138 rl 422 );! Index Regular grammar, 122 Regular sets, 137 closure properties of, 165-167 and regular grammar, 167 Relations reflexive, 41 symmetric, 41 transitive, 41 Right-linear grammar, 226 Ring, 39 Root, 50 Russels paradox, 320 SAT problem (satisfiability problem), 353 Self-embedding grammar, 226 Semigroup, 38 Sentence, 110 Sentential form, 110 Sets, 36, 37, 38, 39, 40 complement of, 37 intersection of, 37 union of, 37 Simple graph, 70 Start symbol, 109 Statement (see Proposition) String empty, 54 length of, 55 operations on, 54 prefix of, 55 suffix of, 55 Strong Church-Turing thesis, 363 Subroutines, 290 Successor, 48 Symmetric difference, 68 Tautology, Time complexity, 294, 349 Top-down parsing, 252 Top-down parsing, using deterministic pda's 256 Transition function, 73, 78, 228 properties of, 75-76 Transition system, 74 containing A-moves, 140 and regular grammar, 169 Transitive closure, 43 Transpose, 55 Travelling salesman problem, 359 Tree 49 height of, 51 properties of, 49-50 Turing-computable functions, 333 Turing machine, 277 construction of, to compute the projection function 336 construction of, to compute the successor function, 335 construction of, to compute the zero function, 334 construction of, to pertorm composition, 338 construction of, to perform minimization 340 construction of, to perform recursion, 339 description of, 289 design of, 284 multiple track, 290 multitape, 292 nondetenninistic, 295 representation by 10, 279 representation by transition diagram, 281 representation by transition table, 280 and type grammar, 299-301 Type grammar (see Grammar) Type grarmnar (see Context-sensitive grammar) Type grammar (see Context-free grammar) Type grammar (see Regular grammar) Unambiguous grammar, 271 Undecidable language, 313 Unit production, 199 elimination of, 199-201 Valid argument, 15 predicate formula, 22 Variable 109 Vertex, 47 ancestor of 51 degree of, 48 descendant of, 51 son of 51 Well-formed formula, or predicate calculus, 21