E-Book Overview
Aho and Ullman have created a C version of their groundbreaking text. As in that text, this book combines the theoretical foundations of computing with essential discrete mathematics. It follows the same organizations as its predecessor, with all examples and exercises in C.
E-Book Content
TABLE OF CONTENTS ✦ ✦ ✦ ✦ Table of Contents Preface Chapter 1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 1.7. 1.8. ix 1. Computer Science: The Mechanization of Abstraction What This Book Is About 3 What This Chapter Is About 6 Data Models 6 The C Data Model 13 Algorithms and the Design of Programs 20 Some C Conventions Used Throughout the Book 22 Summary of Chapter 1 23 Bibliographic Notes for Chapter 1 24 Chapter 2. Iteration, Induction, and Recursion 25 2.1. What This Chapter Is About 27 2.2. Iteration 27 2.3. Inductive Proofs 34 2.4. Complete Induction 44 2.5. Proving Properties of Programs 52 2.6. Recursive Definitions 59 2.7. Recursive Functions 69 2.8. Merge Sort: A Recursive Sorting Algorithm 75 2.9. Proving Properties of Recursive Programs 84 2.10. Summary of Chapter 2 87 2.11. Bibliographic Notes for Chapter 2 88 Chapter 3. The Running Time of Programs 89 3.1. What This Chapter Is About 89 3.2. Choosing an Algorithm 90 3.3. Measuring Running Time 91 3.4. Big-Oh and Approximate Running Time 96 3.5. Simplifying Big-Oh Expressions 101 3.6. Analyzing the Running Time of a Program 109 3.7. A Recursive Rule for Bounding Running Time 116 3.8. Analyzing Programs with Function Calls 127 3.9. Analyzing Recursive Functions 132 3.10. Analysis of Merge Sort 136 3.11. Solving Recurrence Relations 144 3.12. Summary of Chapter 3 154 3.13. Bibliographic Notes for Chapter 3 155 Chapter 4.1. 4.2. 4.3. 4.4. 4. Combinatorics and Probability 156 What This Chapter Is About 156 Counting Assignments 157 Counting Permutations 160 Ordered Selections 167 1 v vi TABLE OF CONTENTS 4.5. Unordered Selections 170 4.6. Orderings With Identical Items 178 4.7. Distribution of Objects to Bins 181 4.8. Combining Counting Rules 184 4.9. Introduction to Probability Theory 187 4.10. Conditional Probability 193 4.11. Probabilistic Reasoning 203 4.12. Expected Value Calculations 212 4.13. Some Programming Applications of Probability 4.14. Summary of Chapter 4 220 4.15. Bibliographic Notes for Chapter 4 221 Chapter 5. The Tree Data Model 223 5.1. What This Chapter Is About 223 5.2. Basic Terminology 224 5.3. Data Structures for Trees 231 5.4. Recursions on Trees 239 5.5. Structural Induction 248 5.6. Binary Trees 253 5.7. Binary Search Trees 258 5.8. Efficiency of Binary Search Tree Operations 268 5.9. Priority Queues and Partially Ordered Trees 271 5.10. Heapsort: Sorting with Balanced POTs 280 5.11. Summary of Chapter 5 284 5.12. Bibliographic Notes for Chapter 5 285 Chapter 6. The List Data Model 286 6.1. What This Chapter Is About 286 6.2. Basic Terminology 287 6.3. Operations on Lists 291 6.4. The Linked-List Data Structure 293 6.5. Array-Based Implementation of Lists 301 6.6. Stacks 306 6.7. Implementing Function Calls Using a Stack 6.8. Queues 318 6.9. Longest Common Subsequences 321 6.10. Representing Character Strings 327 6.11. Summary of Chapter 6 334 6.12. Bibliographic Notes for Chapter 6 335 Chapter 7.1. 7.2. 7.3. 7.4. 7.5. 7.6. 7.7. 7.8. 7.9. 7. The Set Data Model 337 What This Chapter Is About 337 Basic Definitions 338 Operations on Sets 342 List Implementation of Sets 351 Characteristic-Vector Implementation of Sets Hashing 360 Relations and Functions 366 Implementing Functions as Data 373 Implementing Binary Relations 380 312 357 215 TABLE OF CONTENTS 7.10. 7.11. 7.12. 7.13. Some Special Properties of Binary Relations Infinite Sets 396 Summary of Chapter 7 401 Bibliographic Notes for Chapter 7 402 386 Chapter