8 9 t 5 , s(cid:127) 6, 71 c 77 #1 1O A-8 19 2 __ 1 21 2 Hit 809 #10 21 2) A14 1 T3...I3 1 16 18 it, 115 4i8111 Theory of Computing A Gentle Introduction Theory of Computing A Gentle Introduction Efim Kinber Sacred Heart University Carl Smith University of Maryland PRENTICE HALL, Upper Saddle River, New Jersey 07458 Library of Congress Cataloging-in-Publication Data Kinber, Efim Theory of computing: a gentle introduction / Carl Smith, Efim Kinber, p. cm. Includes bibliological references and index. ISBN: 0-13-027961-7 1. Electronic data processing. I. Smith, Carl, 1950 April 25 - II. Title. QA76 .K475 2001 004-dc2l 00-024617 Acquisition Editor: Petra J. Recter Editorial Assistant: Sarah Burrows Vice President and Editorial Director of Engineering and Computer Science: Marcia Horton Assistant Vice President and Director of Production and Manufacturing, ESM: David W. Riccardi Editorial/Production Supervision: BarbaraA . Till Managing Editor: David A. George Executive Managing Editor: Vince O'Brien Manufacturing Buyer: Pat Brown Manufacturing Manager: Trudy Pisciotti Senior Marketing Manager: Jennie Burger Marketing Assistant: Cynthia Szollose Creative Director: Paul Belfanti Art Director: Jayne Conte Cover Designer: Bruce Kenselaar 0© 200L by Prentice-Hall, Inc. Upper Saddle River, New Jersey 07458 All rights reserved. No part of this book may be reproduced, in any form or by any means, without permission in writing from the publisher. The author and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The author and publisher make no warranty of any kind, expressed or implied, with regard to these programs or the documentation contained in this book. The author and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs. Printed in the United States of America 10 9 8 7 6 5 4 3 2 0-13-027961-7 Prentice-Hall International (UK) Limited, London Prentice-Hall of Australia Pty. Limited, Sydney Prentice-Hall Canada Inc., Toronto Prentice-Hall Hispanoamericana, S.A., Mexico Prentice-Hall of ndia Private. Limited, New Delhi Prentice-Hall of Japan, Inc.,Tokyo Pearson Education Asia Pte. Ltd. Editor Prentice-Hall do Brasil, Ltda., Rio de Janeiro Dedicated to those who created the material herein and to those who taught it to us. Contents Preface xiii 1 Introduction 1 1.1 Why Study the Theory of Computing? . . . .. . . . . . . . . . . . . .. . . . 3 1.2 What Is Computation? ................................. 3 1.3 The Contents of This Book ....... ....................... 4 1.4 Mathematical Preliminaries .............................. 5 Exercises ........... .................................... 9 2 Finite Automata 11 2.1 Deterministic Finite Automata ........................... 13 2.2 Nondeterministic Finite Automata ......................... 20 2.3 Determinism versus Nondeterminism ........................ 23 2.4 Regular Expressions ........ ........................... 29 2.5 Nonregular Languages ........ .......................... 43 2.6 Algorithms for Finite Automata ........................... 47 2.7 The State Minimization Problem .......................... 48 Exercises ............................................... 54 3 Context-Free Languages 67 3.1 Context-Free Grammars ................................ 69 3.2 Parsing .......... .................................. 76 3.3 Pushdown Automata .................................. 79 3.4 Languages and Automata ............................... 86 3.5 Closure Properties ........ ............................ 91 3.6 Languages That Are Not Context-Free ...................... 94 3.7 Chomsky Normal Form ........ ......................... 98 3.8 Determinism ........ ............................... 105 Exercises ............................................... 110 4 Turing Machines 119 4.1 Definition of a Turing Machine ........................... 121 vii viii CONTENTS 4.2 Computations by Turing Machines ................... 130 4.3 Extensions of Turing Machines ..................... 134 4.3.1 Multiple Tapes ................................. 134 4.3.2 Multiple Heads ................................. 138 4.3.3 Two-Dimensional Tapes ........................... 139 4.3.4 Random Access Turing Machines ..................... 140 4.4 Nondeterministic Turing Machines ........................ 145 4.5 Turing Enumerable Languages ...... ..................... 148 Exercises ........... .................................... 151 5 Undecidability 157 5.1 The Church-Turing Thesis ............................... 159 5.2 Universal Turing Machines .............................. 161 5.3 The Halting Problem .................................. 162 5.4 Undecidable Problems ................................. 167 Exercises ........... .................................... 172 6 Computational Complexity 175 6.1 The Definition and the Class P ........................... 177 6.2 The Class AýP ......... .............................. 182 6.3 AHP-Completeness ........ ............................ 189 Exercises ........... .................................... 195 References 199 List of Symbols 202 Index 202 List of Figures 1.1 A Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.1 A Finite Automaton ........ ........................... 15 2.2 State Transition Diagram ....... ........................ 16 2.3 Recognizing Two Consecutive a's .......................... 16 2.4 Recognizing the Complement ....... ...................... 17 2.5 Mystery Automaton 1 ........ .......................... 17 2.6 Mystery Automaton 2 ........ .......................... 18 2.7 Recognizing an Even Number of a's and Odd Number of b's ..... .. 19 2.8 The Finite State Diagram of a Newspaper Vending Machine ..... .20 2.9 Combining Two Automata ............................... 21 2.10 Accepting All a's or All b's ....... ....................... 22 2.11 Start and End with a b ................................. 23 2.12 With Extra States ........ ............................ 24 2.13 Multiple Possible Transitions ....... ...................... 24 2.14 Replacement Transition ....... ......................... 25 2.15 A New Connection ........ ............................ 25 2.16 An e-Move ......... ................................ 26 2.17 An e-Move Eliminated ................................. 26 2.18 Segment of a Nondeterministic Finite Automaton ............... 27 2.19 Corresponding Deterministic Segment ...................... 27 2.20 Untransformed Automaton ....... ....................... 28 2.21 Transformed Automaton ................................ 29 2.22 Recognizing Strings Containing abbab ...................... 30 2.23 Deterministic Version of Figure 2.22 ........................ 30 2.24 Automaton A ....................................... 32 2.25 Automaton B ....................................... 32 2.26 The Union of A and B ................................. 33 2.27 Concatenation of L and M ...... ....................... 34 2.28 Kleene Star of A ........ ............................. 34 2.29 Singleton Automata ........ ........................... 37 2.30 Transformation Step 1 of 5 ....... ....................... 37 2.31 Transformation Step 2 of 5 ....... ....................... 37 ix x LIST OF FIGURES 2.32 Transformation Step 3 of 5 ....................... 38 2.33 Transformation Step 4 of 5 ....... ....................... 38 2.34 Transformation Step 5 of 5 ....... ....................... 39 2.35 An Expression Diagram ....... ......................... 39 2.36 Initial Automaton ........ ............................ 40 2.37 Converted Automaton ........ .......................... 40 2.38 Automaton with One Accepting State ...................... 41 2.39 Steps 1, 2 and 3 ...................................... 41 2.40 Example Input for Algorithm B ........................... 42 2.41 Node 2 Deleted ........ .............................. 42 2.42 Node 3 deleted ........ .............................. 42 2.43 Final Expression Diagram ....... ........................ 43 2.44 Automaton with an Unreachable State ...................... 49 2.45 Without the Unreachable State ........................... 50 2.46 Distinguishability of r and r' Related to the Distinguishability of q and q. ......... ................................... 50 2.47 A Minimal Deterministic Finite Automaton ................... 53 3.1 Parse Trees for John bought car ........................... 77 3.2 Parse Tree for the First Derivation of aa ...................... 79 3.3 Parse Tree for the Second Derivation of aa ................... 80 3.4 Pushdown Automaton ........ .......................... 82 3.5 Operation of the Automaton Accepting abbbaaaabb ............. 85 3.6 Computation of Automaton A on ababbaba ..... .............. 87 3.7 Schematic Parse Tree for w ....... ....................... 90 3.8 Schematic Parse Tree for w = uvxyz ...... .................. 96 4.1 A Turing Machine ........ ............................ 123 4.2 A Sequence of Turing Machines ........................... 126 4.3 Branching Turing Machines ...... ....................... 127 4.4 A Loop ......... .................................. 127 4.5 Writing b over a ........ ............................. 128 4.6 Moving Right and Writing a ............................. 128 4.7 Erasing the Input .................................... 128 4.8 Finding the First Blank on the Right ....................... 129 4.9 The Copying Machine Cp ....... ........................ 130 4.10 Computing the Function f(w) = wa ........................ 131 4.11 The Shifting Machine Shl ....... ........................ 132 4.12 Multitape Turing Machine ............................... 135 4.13 A Multitrack Tape ....... ............................ 136 4.14 Simulating k Tapes by 2k Tracks .......................... 136 4.15 Initial Configuration of Tracks ...... ..................... 137 4.16 Two-Dimensional Tape with Numbered Cells ................. 140 4.17 Simulation of a Two-Dimensional Tape in One Dimension ...... .140 LIST OF FIGURES xi 4.18 Random Access Thring Machine .................... 141 4.19 Commands of RAM Machine ...................... 142 4.20 Dovetailing . .... ...... .... .... ..... ..... ... 146 4.21 The Tree of Nondeterministic Computations .............. 147 5.1 U after Initialization on (M )(w) .................... 163 5.2 The Diagonal Function ................................. 164 5.3 The Program CONTR ................................. 165 6.1 An Undirected Weighted Graph .......................... 180 6.2 A Graph with a Hamiltonian Cycle ........................ 184 6.3 A Clique of Size 4 ........ ............................ 184 6.4 Algorithm A ........ ............................... 190 6.5 The Graph Derived from a Boolean Formula f ............ 193
Description: