ebook img

Algorithms, Part II PDF

437 Pages·2013·10.67 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Algorithms, Part II

ptg12441863 Algorithms FOURTH EDITION PART II ptg12441863 This page intentionally left blank ptg12441863 Algorithms FOURTH EDITION PART II ptg12441863 Robert Sedgewick and Kevin Wayne Princeton University Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or im- plied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, ptg12441863 marketing focus, or branding interests), please contact our corporate sales department at (800) 382-3419 or [email protected]. For government sales inquiries, please contact [email protected]. For questions about sales outside the United States, please contact [email protected]. Visit us on the Web: informit.com/aw Copyright © 2014 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retriev- al system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290. ISBN-13: 978-0-13-379911-8 ISBN-10: 0-13-379911-5 First digital release, February 2014 ______________________________ To Adam, Andrew, Brett, Robbie and especially Linda ______________________________ ptg12441863 ___________________ To Jackie and Alex ___________________ CONTENTS Note: This is an online edition of Chapters 4 through 6 of Algorithms, Fourth Edition, which con- tains the content covered in our online course Algorithms, Part II. For more information, see http://algs4.cs.princeton.edu. Preface ix Chapters 1 through 3, which correspond to our online course Algorithms, Part I, are available as Algorithms, Fourth Edition, Part I. 4. Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . .515 4.1 Undirected Graphs 518 ptg12441863 Glossary • Undirected graph type • Adjacency-lists representation • Depth-first search • Breadth-first search • Connected components • Degrees of separation 4.2 Directed Graphs 566 Glossary • Digraph data type • Depth-first search • Directed cycle detection • Precedence-constrained scheduling • Topological sort • Strong connectivity • Kosaraju-Sharir algorithm • Transitive closure 4.3 Minimum Spanning Trees 604 Cut property • Greedy algorithm • Edge-weighted graph data type • Prim’s algorithm • Kruskal’s algorithm 4.4 Shortest Paths 638 Properties of shortest paths • Edge-weighted digraph data types • Generic shortest paths algorithm • Dijkstra’s algorithm • Shortest paths in edge- weighted DAGs • Critical-path method • Bellman-Ford algorithm • Negative cycle detection • Arbitrage 5. Strings . . . . . . . . . . . . . . . . . . . . . . . . . . .695 5.1 String Sorts 702 Key-indexed counting • LSD string sort • MSD string sort • 3-way string quicksort 5.2 Tries 730 String symbol table API • R-way tries • Ternary search tries • Character- based operations 5.3 Substring Search 758 Brute-force algorithm • Knuth-Morris-Pratt algorithm • Boyer-Moore algorithm • Rabin-Karp fingerprint algorithm 5.4 Regular Expressions 788 Describing patterns with REs • Applications • Nondeterministic finite-state automata • Simulating an NFA • Building an NFA corresponding to an RE 5.5 Data Compression 810 Rules of the game • Reading and writing binary data • Limitations • Run-length coding • Huffman compression • LZW compression ptg12441863 6. Context . . . . . . . . . . . . . . . . . . . . . . . . . . .853 Event-Driven Simulation 856 Hard-disc model • Collision prediction • Collision resolution B-trees 866 Cost model • Search and insert Suffix Arrays 875 Suffix sorting • Longest repeated substring • Keyword in context Network–Flow Algorithms 886 Maximum flow • Minimum cut • Ford-Fulkerson algorithm Reduction 903 Sorting • Shortest path • Bipartite matching • Linear programming Intractability 910 Longest-paths problem • P vs. NP • Boolean satisfiability • NP-completeness This page intentionally left blank ptg12441863 PREFACE T his book is intended to survey the most important computer algorithms in use today, and to teach fundamental techniques to the growing number of people in need of knowing them. It is intended for use as a textbook for a second course in computer science, after students have acquired basic programming skills and familiarity with computer systems. The book also may be useful for self-study or as a reference for people engaged in the development of computer systems or applications programs, since it contains implemen- ptg12441863 tations of useful algorithms and detailed information on performance characteristics and clients. The broad perspective taken makes the book an appropriate introduction to the field. the study of algorithms and data structures is fundamental to any computer- science curriculum, but it is not just for programmers and computer-science students. Every- one who uses a computer wants it to run faster or to solve larger problems. The algorithms in this book represent a body of knowledge developed over the last 50 years that has become indispensable. From N-body simulation problems in physics to genetic-sequencing problems in molecular biology, the basic methods described here have become essential in scientific research; from architectural modeling systems to aircraft simulation, they have become es- sential tools in engineering; and from database systems to internet search engines, they have become essential parts of modern software systems. And these are but a few examples—as the scope of computer applications continues to grow, so grows the impact of the basic methods covered here. In Chapter 1, we develop our fundamental approach to studying algorithms, includ- ing coverage of data types for stacks, queues, and other low-level abstractions that we use throughout the book. In Chapters 2 and 3, we survey fundamental algorithms for sorting and searching; and in Chapters 4 and 5, we cover algorithms for processing graphs and strings. Chapter 6 is an overview placing the rest of the material in the book in a larger context. ix

Description:
Cut property • Greedy algorithm • Edge-weighted graph data type • . gramming in Java: An Interdisciplinary Approach, which is a broad introduction
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.