TABLE OF CONTENTS V Table Of Contents

3y ago
55 Views
2 Downloads
5.96 MB
884 Pages
Last View : 15d ago
Last Download : 3m ago
Upload by : Maxine Vice
Transcription

TABLE OF CONTENTS Table of 1.8.ix1. Computer Science: The Mechanization of AbstractionWhat This Book Is About 3What This Chapter Is About 6Data Models 6The C Data Model 13Algorithms and the Design of Programs 20Some C Conventions Used Throughout the Book 22Summary of Chapter 1 23Bibliographic Notes for Chapter 1 24Chapter 2. Iteration, Induction, and Recursion 252.1. What This Chapter Is About 272.2. Iteration 272.3. Inductive Proofs 342.4. Complete Induction 442.5. Proving Properties of Programs 522.6. Recursive Definitions 592.7. Recursive Functions 692.8. Merge Sort: A Recursive Sorting Algorithm 752.9. Proving Properties of Recursive Programs 842.10. Summary of Chapter 2 872.11. Bibliographic Notes for Chapter 2 88Chapter 3. The Running Time of Programs 893.1. What This Chapter Is About 893.2. Choosing an Algorithm 903.3. Measuring Running Time 913.4. Big-Oh and Approximate Running Time 963.5. Simplifying Big-Oh Expressions 1013.6. Analyzing the Running Time of a Program 1093.7. A Recursive Rule for Bounding Running Time 1163.8. Analyzing Programs with Function Calls 1273.9. Analyzing Recursive Functions 1323.10. Analysis of Merge Sort 1363.11. Solving Recurrence Relations 1443.12. Summary of Chapter 3 1543.13. Bibliographic Notes for Chapter 3 155Chapter4.1.4.2.4.3.4.4.4. Combinatorics and Probability 156What This Chapter Is About 156Counting Assignments 157Counting Permutations 160Ordered Selections 1671v

viTABLE OF CONTENTS4.5. Unordered Selections 1704.6. Orderings With Identical Items 1784.7. Distribution of Objects to Bins 1814.8. Combining Counting Rules 1844.9. Introduction to Probability Theory 1874.10. Conditional Probability 1934.11. Probabilistic Reasoning 2034.12. Expected Value Calculations 2124.13. Some Programming Applications of Probability4.14. Summary of Chapter 4 2204.15. Bibliographic Notes for Chapter 4 221Chapter 5. The Tree Data Model 2235.1. What This Chapter Is About 2235.2. Basic Terminology 2245.3. Data Structures for Trees 2315.4. Recursions on Trees 2395.5. Structural Induction 2485.6. Binary Trees 2535.7. Binary Search Trees 2585.8. Efficiency of Binary Search Tree Operations 2685.9. Priority Queues and Partially Ordered Trees 2715.10. Heapsort: Sorting with Balanced POTs 2805.11. Summary of Chapter 5 2845.12. Bibliographic Notes for Chapter 5 285Chapter 6. The List Data Model 2866.1. What This Chapter Is About 2866.2. Basic Terminology 2876.3. Operations on Lists 2916.4. The Linked-List Data Structure 2936.5. Array-Based Implementation of Lists 3016.6. Stacks 3066.7. Implementing Function Calls Using a Stack6.8. Queues 3186.9. Longest Common Subsequences 3216.10. Representing Character Strings 3276.11. Summary of Chapter 6 3346.12. Bibliographic Notes for Chapter 6 335Chapter7.1.7.2.7.3.7.4.7.5.7.6.7.7.7.8.7.9.7. The Set Data Model 337What This Chapter Is About 337Basic Definitions 338Operations on Sets 342List Implementation of Sets 351Characteristic-Vector Implementation of SetsHashing 360Relations and Functions 366Implementing Functions as Data 373Implementing Binary Relations 380312357215

TABLE OF CONTENTS7.10.7.11.7.12.7.13.Some Special Properties of Binary RelationsInfinite Sets 396Summary of Chapter 7 401Bibliographic Notes for Chapter 7 402386Chapter 8. The Relational Data Model 4038.1. What This Chapter Is About 4038.2. Relations 4048.3. Keys 4118.4. Primary Storage Structures for Relations 4148.5. Secondary Index Structures 4198.6. Navigation among Relations 4238.7. An Algebra of Relations 4288.8. Implementing Relational Algebra Operations 4368.9. Algebraic Laws for Relations 4408.10. Summary of Chapter 8 4498.11. Bibliographic Notes for Chapter 8 450Chapter 9. The Graph Data Model 4519.1. What This Chapter Is About 4519.2. Basic Concepts 4529.3. Implementation of Graphs 4599.4. Connected Components of an Undirected Graph9.5. Minimal Spanning Trees 4789.6. Depth-First Search 4849.7. Some Uses of Depth-First Search 4959.8. Dijkstra’s Algorithm for Finding Shortest Paths9.9. Floyd’s Algorithm for Shortest Paths 5139.10. An Introduction to Graph Theory 5219.11. Summary of Chapter 9 5269.12. Bibliographic Notes for Chapter 9 527466502Chapter 10. Patterns, Automata, and Regular Expressions 52910.1. What This Chapter Is About 53010.2. State Machines and Automata 53010.3. Deterministic and Nondeterministic Automata 53610.4. From Nondeterminism to Determinism 54710.5. Regular Expressions 55610.6. The UNIX Extensions to Regular Expressions 56410.7. Algebraic Laws for Regular Expressions 56810.8. From Regular Expressions to Automata 57110.9. From Automata to Regular Expressions 58210.10. Summary of Chapter 10 58810.11. Bibliographic Notes for Chapter 10 589Chapter 11. Recursive Description of Patterns11.1. What This Chapter Is About 59111.2. Context-Free Grammars 59211.3. Languages from Grammars 59911.4. Parse Trees 602591vii

viiiTABLE OF CONTENTS11.5. Ambiguity and the Design of Grammars 61011.6. Constructing Parse Trees 61711.7. A Table-Driven Parsing Algorithm 62511.8. Grammars Versus Regular Expressions 63411.9. Summary of Chapter 11 64011.10. Bibliographic Notes for Chapter 11 641Chapter 12. Propositional Logic 64212.1. What This Chapter Is About 64212.2. What Is Propositional Logic? 64312.3. Logical Expressions 64512.4. Truth Tables 64912.5. From Boolean Functions to Logical Expressions 65512.6. Designing Logical Expressions by Karnaugh Maps 66012.7. Tautologies 66912.8. Some Algebraic Laws for Logical Expressions 67412.9. Tautologies and Methods of Proof 68212.10. Deduction 68612.11. Proofs by Resolution 69212.12. Summary of Chapter 12 69712.13. Bibliographic Notes for Chapter 12 698Chapter 13. Using Logic to Design Computer Components13.1. What This Chapter is About 69913.2. Gates 70013.3. Circuits 70113.4. Logical Expressions and Circuits 70513.5. Some Physical Constraints on Circuits 71113.6. A Divide-and-Conquer Addition Circuit 71613.7. Design of a Multiplexer 72313.8. Memory Elements 73013.9. Summary of Chapter 13 73113.10. Bibliographic Notes for Chapter 13 732Chapter 14. Predicate Logic 73314.1. What This Chapter Is About 73314.2. Predicates 73414.3. Logical Expressions 73614.4. Quantifiers 73914.5. Interpretations 74514.6. Tautologies 75114.7. Tautologies Involving Quantifiers 75314.8. Proofs in Predicate Logic 75914.9. Proofs from Rules and Facts 76214.10. Truth and Provability 76814.11. Summary of Chapter 14 77414.12. Bibliographic Notes for Chapter 14 775Index776699

PrefaceThis book was motivated by the desire we and others have had to further the evolution of the core course in computer science. Many departments across the countryhave revised their curriculum in response to the introductory course in the scienceof computing discussed in the “Denning Report,” (Denning, P. J., D. E. Comer, D.Gries, M. C. Mulder, A. Tucker, J. Turner, and P. R. Young, “Computing as a Discipline,” Comm. ACM 32:1, pp. 9–23, January 1989.). That report draws attentionto three working methodologies or processes — theory, abstraction, and design —as fundamental to all undergraduate programs in the discipline. More recently,the Computing Curricula 1991 report of the joint ACM/IEEE-CS Curriculum TaskForce echoes the Denning Report in identifying key recurring concepts which arefundamental to computing, especially: conceptual and formal models, efficiency,and levels of abstraction. The themes of these two reports summarize what we havetried to offer the student in this book.This book developed from notes for a two-quarter course at Stanford — calledCS109: Introduction to Computer Science — that serves a number of goals. Thefirst goal is to give beginning computer science majors a solid foundation for further study. However, computing is becoming increasingly important in a muchwider range of scientific and engineering disciplines. Therefore, a second goal isto give those students who will not take advanced courses in computer science theconceptual tools that the field provides. Finally, a more pervasive goal is to exposeall students not only to programming concepts but also to the intellectually richfoundations of the field.Our first version of this book was based on programming in Pascal and appearedin 1992. Our choice of Pascal as the language for example programs was motivatedby that language’s use in the Computer Science Advanced Placement Test as wellas in a plurality of college introductions to programming. We were pleased to seethat since 1992 there has been a significant trend toward C as the introductoryprogramming language, and we accordingly developed a new version of the bookusing C for programming examples. Our emphasis on abstraction and encapsulationshould provide a good foundation for subsequent courses covering object-orientedtechnology using C .At the same time, we decided to make two significant improvements in thecontent of the book. First, although it is useful to have a grounding in machinearchitecture to motivate how running time is measured, we found that almost allcurricula separate architecture into a separate course, so the chapter on that subjectwas not useful. Second, many introductory courses in the theory of computingemphasize combinatorics and probability, so we decided to increase the coverageand cluster the material into a chapter of its own.Foundations of Computer Science covers subjects that are often found splitbetween a discrete mathematics course and a sophomore-level sequence in computerscience in data structures. It has been our intention to select the mathematicalfoundations with an eye toward what the computer user really needs, rather thanwhat a mathematician might choose. We have tried to integrate effectively themathematical foundations with the computing. We thus hope to provide a betterfeel for the soul of computer science than might be found in a programming course,ix

xPREFACEa discrete mathematics course, or a course in a computer science subspecialty. Webelieve that, as time goes on, all scientists and engineers will take a foundationalcourse similar to the one offered at Stanford upon which this book is based. Such acourse in computer science should become as standard as similar courses in calculusand physics.PrerequisitesStudents taking courses based on this book have ranged from first-year undergraduates to graduate students. We assume only that students have had a solid coursein programming. They should be familiar with the programming language ANSIC to use this edition. In particular, we expect students to be comfortable with Cconstructs such as recursive functions, structures, pointers, and operators involvingpointers and structures such as dot, - , and &.Suggested Outlines for Foundational Courses in CSIn terms of a traditional computer science curriculum, the book combines a firstcourse in data structures — that is, a “CS2” course — with a course in discretemathematics. We believe that the integration of these subjects is extremely desirable for two reasons:1.It helps motivate the mathematics by relating it more closely to the computing.2.Computing and mathematics can be mutually reinforcing. Some examplesare the way recursive programming and mathematical induction are related inChapter 2 and the way the free/bound variable distinction for logic is relatedto the scope of variables in programming languages in Chapter 14. Suggestionsfor instructive programming assignments are presented throughout the book.There are a number of ways in which this book can be used.A Two-Quarter or Two-Semester CourseThe CS109A-B sequence at Stanford is typical of what might be done in two quarters, although these courses are rather intensive, being 4-unit, 10-week courses each.These two courses cover the entire book, the first seven chapters in CS109A andChapters 8 through 14 in CS109B.A One-Semester “CS2” Type CourseIt is possible to use the book for a one-semester course covering a set of topics similarto what would appear in a “CS2” course. Naturally, there is too much material inthe book to cover in one semester, and so we recommend the following:1.Recursive algorithms and programs in Sections 2.7 and 2.8.2.Big-oh analysis and running time of programs: all of Chapter 3 except forSection 3.11 on solving recurrence relations.3.Trees in Sections 5.2 through 5.10.

PREFACExi4.Lists: all of Chapter 6. Some may wish to cover lists before trees, whichis a more traditional treatment. We regard trees as the more fundamentalnotion, but there is little harm in switching the order. The only significantdependency is that Chapter 6 talks about the “dictionary” abstract data type(set with operations insert, delete, and lookup), which is introduced in Section5.7 as a concept in connection with binary search trees.5.Sets and relations. Data structures for sets and relations are emphasized inSections 7.2 through 7.9 and 8.2 through 8.6.6.Graph algorithms are covered in Sections 9.2 through 9.9.A One-Semester Discrete Mathematics CourseFor a one-semester course emphasizing mathematical foundations, the instructorcould choose to cover:1.2.Mathematical induction and recursive programs in Chapter 2.Big-oh analysis, running time, and recurrence relations in Sections 3.4 through3.11.3. Combinatorics in Sections 4.2 through 4.8.4. Discrete probability in Sections 4.9 through 4.13.5. Mathematical aspects of trees in Sections 5.2 through 5.6.6. Mathematical aspects of sets in Sections 7.2, 7.3, 7.7, 7.10, and 7.11.7. The algebra of relations in Sections 8.2, 8.7, and 8.9.8. Graph algorithms and graph theory in Chapter 9.9. Automata and regular expressions in Chapter 10.10. Context-free grammars in Sections 11.2 through 11.4.11. Propositional and predicate logic in Chapters 12 and 14, respectively.Features of This BookTo help the student assimilate the material, we have added the following study aids:1.Each chapter has an outline section at the beginning and a summary sectionat the end highlighting the main points.2.Marginal notes mark important concepts and definitions. However, items mentioned in section or subsection headlines are not repeated in the margin.3.“Sidebars” are separated from the text by double lines. These short notes serveseveral purposes: Some are elaborations on the text or make some fine points about programor algorithm design. Others are for summary or emphasis of points made in the text nearby.These include outlines of important kinds of proofs, such as the variousforms of proof by induction. A few are used to give examples of fallacious arguments, and we hope thatthe separation from the text in this way will eliminate possible misconstruction of the point.

xiiPREFACE A few give very brief introductions to major topics like undecidability orthe history of computers to which we wish we could devote a full section.4.Most of the sections end with exercises. There are more than 1000 exercisesor parts spread among the sections. Of these roughly 30% are marked with asingle star, which indicates that they require more thought than the unstarredexercises. Approximately another 10% of the exercises are doubly starred, andthese are the most challenging.5.Chapters end with bibliographic notes. We have not attempted to be exhaustive, but offer suggestions for more advanced texts on the subject of the chapterand mention the relevant papers with the most historical significance.About the CoverIt is a tradition for computer science texts to have a cover with a cartoon or drawingsymbolizing the content of the book. Here, we have drawn on the myth of the worldas the back of a turtle, but our world is populated with representatives of some ofthe other, more advanced texts in computer science that this book is intended tosupport. They are:The teddy bear: R. Sethi, Programming Languages: Concepts and Constructs,Addison-Wesley, Reading, Mass., 1989.The baseball player: J. D. Ullman, Principles of Database and Knowledge-BaseSystems, Computer Science Press, New York, 1988.The column: J. L. Hennessy and D. A. Patterson, Computer Architecture: a Quantitative Approach, Morgan-Kaufmann, San Mateo, Calif., 1990.The dragon: A. V. Aho, R. Sethi, and J. D. Ullman, Compiler Design: Principles,Techniques, and Tools, Addison-Wesley, Reading, Mass., 1986.The triceratops: J. L. Peterson and A. Silberschatz, Operating Systems Concepts,second edition, Addison-Wesley, Reading, Mass., 1985.AcknowledgmentsWe are deeply indebted to a number of colleagues and students who have read thismaterial and given us many valuable suggestions for improving the presentation.We owe a special debt of gratitude to Brian Kernighan, Don Knuth, ApostolosLerios, and Bob Martin who read the original Pascal manuscript in detail andgave us many perceptive comments. We have received, and gratefully acknowledge,reports of course testing of the notes for the Pascal edition of this book by MichaelAnderson, Margaret Johnson, Udi Manber, Joseph Naor, Prabhakar Ragde, RockyRoss, and Shuky Sagiv.There are a number of other people who found errors in earlier editions, boththe original notes and the various printings of the Pascal edition. In this regard,we would like to thank: Susan Aho, Michael Anderson, Aaron Edsinger, LonnieEldridge, Todd Feldman, Steve Friedland, Christopher Fuselier, Mike Genstil, PaulGrubb III, Barry Hayes, John Hwang, Hakan Jakobsson, Arthur Keller, Dean Kelley,James Kuffner Jr., Steve Lindell, Richard Long, Mark MacDonald, Simone Martini, Hugh McGuire, Alan Morgan, Monnia Oropeza, Rodrigo Philander, AndrewQuan, Stuart Reges, John Stone, Keith Swanson, Steve Swenson, Sanjai Tiwari,Eric Traut, and Lynzi Ziegenhagen.

PREFACExiiiWe acknowledge helpful advice from Geoff Clem, Jon Kettenring, and BrianKernighan during the preparation of the C edition of Foundations of ComputerScience.Peter Ullman produced a number of the figures used in this book. We are grateful to Dan Clayton, Anthony Dayao, Mat Howard, and Ron Underwood for helpwith TEX fonts, and to Hester Glynn and Anne Smith for help with the manuscriptpreparation.On-Line Access to Code, Errata, and NotesYou can obtain copies of the major programs in this book by anonymous ftp to hostftp-cs.stanford.edu. Login with user name anonymous and give your name andhost as a password. You may then executecd fcscwhere you will find programs from this book. We also plan to keep in this directoryinformation about errata and what course notes we can provide.A. V. A.Chatham, NJJ. D. U.Stanford, CAJuly, 1994

CHAPTER AbstractionExamscheduling1Computer Science:The Mechanizationof AbstractionThough it is a new field, computer science already touches virtually every aspectof human endeavor. Its impact on society is seen in the proliferation of computers,information systems, text editors, spreadsheets, and all of the wonderful applicationprograms that have been developed to make computers easier to use and people moreproductive. An important part of the field deals with how to make programmingeasier and software more reliable. But fundamentally, computer science is a scienceof abstraction — creating the right model for thinking about a problem and devisingthe appropriate mechanizable techniques to solve it.Every other science deals with the universe as it is. The physicist’s job, forexample, is to understand how the world works, not to invent a world in whichphysical laws would be simpler or more pleasant to follow. Computer scientists,on the other hand, must create abstractions of real-world problems that can beunderstood by computer users and, at the same time, that can be represented andmanipulated inside a computer.Sometimes the process of abstraction is simple. For example, we can model thebehavior of the electronic circuits used to build computers quite well by an abstraction called “propositional logic.” The modeling of circuits by logical expressions isnot exact; it simplifies, or abstracts away, many details — such as the time it takesfor electrons to flow

TABLE OF CONTENTS v Table of Contents Preface ix Chapter 1. Computer Science: The Mechanization of Abstraction 1 1.1. What This Book Is About 3 1.2. What This Chapter Is About 6 1.3. Data Models 6 1.4. The C Data Model 13 1.5. Algorithms and the Design of Programs 20 1.6. Some C Conventions Used Throughout the Book 22 1.7. Summary of Chapter 1 .

Related Documents:

Creating a table of contents The Insert Index/Table window (Figure 1) has five tabs. All of them can be used when creating a table of contents: Use the Index/Table tab to set the attributes of the table of contents. Use the Entries and Styles tabs to format the entries in the table of contents. Use the Background tab to add color or a graphic to the background of the table of

Word. Modifying the appearance To change how the table of contents looks – font type, size, indentation etc. – click in the table and on Table of Contents on the References tab, then choose Custom Table of Contents again. In the Table of Contents dialog box, click the Modify button to

The TABLE OF CONTENTS will have shifted. If you need to re-insert the TABLE OF CONTENTS, this margin fix will not stay in place. You will have to follow the temporary fix again OR make a permanent fix to the TABLE OF CONTENTS. Permanent fix: Place your cursor at the first entry in the TABLE OF CONTENTS.

Creating a table of contents The Insert/Index Table window has five tabs. Four of them are used when creating a table of contents: Use the Index/Table tab to set the table's attributes. Use the Entries and Styles tabs to format the table entries. Use the Background tab to add color or a graphic to the table background. The next four sections of this chapter tell you how to use each . /p div class "b_factrow b_twofr" div class "b_vlist2col" ul li div strong File Size: /strong 554KB /div /li /ul ul li div strong Page Count: /strong 15 /div /li /ul /div /div /div

table of contents reviewed early. It is proposed that, in the digital environment, " the table of contents needs to be generated automatically to reflect the dynamic feature of "digital books" and online collections. the table of contents needs to provide an overview to contents of the documents it covers; the overview

The Yajur Veda (Taittiriya Sanhita) x. Table of Contents The Yajur Veda (Taittiriya Sanhita) Table of Contents. Table of Contents. Table of Contents. Yajur Veda Kanda I PRAPATHAKA VII ii. 3. 11. ii. 3. 12. PRAPATHAKA VII v. 6. 20.

Table of Contents(TOC) Formatting your heading has now made it possible to insert an automatic table of contents. It is usually placed directly before the Introduction. If you already have a heading for the table of contents, select the row below it. Under References, click Table of Contents and

Petitioner-Appellee Albert Woodfox once again before this Courtis in connection with his federal habeas petition.The district c ourt had originally granted Woodfox federal habeas relief on the basis of ineffective assistance of counsel, but weheld that the district court erred in light of the deferential review affordedto state courts under the Antiterrorism and Effective Death Penalty Act of .