Addison wesley algorithms in java parts 1 4 3rd edition aug 2002 ISBN 0201361205

414 44 0
Addison wesley algorithms in java parts 1 4 3rd edition aug 2002 ISBN 0201361205

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Algorithms in Java: Parts 1-4, Third Edition By Robert Sedgewick Publisher: Addison W esley Pub Date: July 23, 2002 ISBN: 0-201-36120-5, 768 pages Sedgew ick has a real gift for explaining concepts in a w ay that makes them easy to understand The use of real programs in page-size (or less) chunks that can be easily understood is a real plus The figures, programs, and tables are a significant contribution to the learning experience of the reader; they make this book distinctive.-W illiam A W ard, University of South Alabama This edition of Robert Sedgew ick's popular w ork provides current and comprehensive coverage of important algorithms for Java programmers Michael Schidlow sky and Sedgew ick have developed new Java implementations that both express the methods in a concise and direct manner and provide programmers w ith the practical means to test them on real applications Many new algorithms are presented, and the explanations of each algorithm are much more detailed than in previous editions A new text design and detailed, innovative figures, w ith accompanying commentary, greatly enhance the presentation The third edition retains the successful blend of theory and practice that has made Sedgew ick's w ork an invaluable resource for more than 400,000 programmers! This particular book, Parts 1-4, represents the essential first half of Sedgew ick's complete w ork It provides extensive coverage of fundamental data structures and algorithms for sorting, searching, and related applications Although the substance of the book applies to programming in any language, the implementations by Schidlow sky and Sedgew ick also exploit the natural match betw een Java classes and abstract data type (ADT) implementations Highlights Java class implementations of more than 100 important practical algorithms Emphasis on ADTs, modular programming, and object-oriented programming Extensive coverage of arrays, linked lists, trees, and other fundamental data structures Thorough treatment of algorithms for sorting, selection, priority queue ADT implementations, and symbol table ADT implementations (search algorithms) Complete implementations for binomial queues, multiw ay radix sorting, randomized BSTs, splay trees, skip lists, multiw ay tries, B trees, extendible hashing, and many other advanced methods Quantitative information about the algorithms that gives you a basis for comparing them More than 1,000 exercises and more than 250 detailed figures to help you learn properties of the algorithms W hether you are learning the algorithms for the first time or w ish to have up-to-date reference material that incorporates new programming styles w ith classic and new algorithms, you w ill find a w ealth of useful information in this book Algorithms in Java: Parts 1-4, Third Edition Copyright Preface Scope Use in the Curriculum Algorithms of Practical Use Programming Language Acknow ledgments Java Consultant's Preface Notes on Exercises Part I: Fundamentals Chapter Introduction Section 1.1 Algorithms Section 1.2 A Sample Problem: Connectivity Section 1.3 Union–Find Algorithms Section 1.4 Perspective Section 1.5 Summary of Topics Chapter Principles of Algorithm Analysis Section 2.1 Implementation and Empirical Analysis Section 2.2 Analysis of Algorithms Section 2.3 Grow th of Functions Section 2.4 Big-Oh Notation Section 2.5 Basic Recurrences Section 2.6 Examples of Algorithm Analysis Section 2.7 Guarantees, Predictions, and Limitations References for Part One Part II: Data Structures Chapter Elementary Data Structures Section 3.1 Building Blocks Section 3.2 Arrays Section 3.3 Linked Lists Section 3.4 Elementary List Processing Section 3.5 Memory Allocation for Lists Section 3.6 Strings Section 3.7 Compound Data Structures Chapter Abstract Data Types Exercises Section 4.1 Collections of Items Section 4.2 Pushdow n Stack ADT Section 4.3 Examples of Stack ADT Clients Section 4.4 Stack ADT Implementations Section 4.5 Generic Implementations Section 4.6 Creation of a New ADT Section 4.7 FIFO Queues and Generalized Queues Section 4.8 Duplicate and Index Items Section 4.9 First-Class ADTs Section 4.10 Application-Based ADT Example Section 4.11 Perspective Chapter Recursion and Trees Section 5.1 Recursive Algorithms Section 5.2 Divide and Conquer Section 5.3 Dynamic Programming Section 5.4 Trees Section 5.5 Mathematical Properties of Binary Trees Section 5.6 Tree Traversal Section 5.7 Recursive Binary-Tree Algorithms Section 5.8 Graph Traversal Section 5.9 Perspective References for Part Tw o Part III: Sorting Chapter Elementary Sorting Methods Section 6.1 Rules of the Game Section 6.2 Generic Sort Implementations Section 6.3 Selection Sort Section 6.4 Insertion Sort Section 6.5 Bubble Sort Section 6.6 Performance Characteristics of Elementary Sorts Section 6.7 Algorithm Visualization Section 6.8 Shellsort Section 6.9 Sorting of Linked Lists Section 6.10 Key-Indexed Counting Chapter Quicksort Section 7.1 The Basic Algorithm Section 7.2 Performance Characteristics of Quicksort Section 7.3 Stack Size Section 7.4 Small Subfiles Section 7.5 Median-of-Three Partitioning Section 7.6 Duplicate Keys Section 7.7 Strings and Vectors Section 7.8 Selection Chapter Merging and Mergesort Section 8.1 Tw o-W ay Merging Section 8.2 Abstract In-Place Merge Section 8.3 Top-Dow n Mergesort Section 8.4 Improvements to the Basic Algorithm Section 8.5 Bottom-Up Mergesort Section 8.6 Performance Characteristics of Mergesort Section 8.7 Linked-List Implementations of Mergesort Section 8.8 Recursion Revisited Chapter Priority Queues and Heapsort Exercises Section 9.1 Elementary Implementations Section 9.2 Heap Data Structure Section 9.3 Algorithms on Heaps Section 9.4 Heapsort Section 9.5 Priority-Queue ADT Section 9.6 Priority Queues for Client Arrays Section 9.7 Binomial Queues Chapter 10 Radix Sorting Section 10.1 Bits, Bytes, and W ords Section 10.2 Binary Quicksort Section 10.3 MSD Radix Sort Section 10.4 Three-W ay Radix Quicksort Section 10.5 LSD Radix Sort Section 10.6 Performance Characteristics of Radix Sorts Section 10.7 Sublinear-Time Sorts Chapter 11 Special-Purpose Sorting Methods Section 11.1 Batcher's Odd–Even Mergesort Section 11.2 Sorting Netw orks Section 11.3 Sorting In Place Section 11.4 External Sorting Section 11.5 Sort–Merge Implementations Section 11.6 Parallel Sort–Merge References for Part Three Part IV: Searching Chapter 12 Symbol Tables and Binary Search Trees Section 12.1 Symbol-Table Abstract Data Type Section 12.2 Key-Indexed Search Section 12.3 Sequential Search Section 12.4 Binary Search Section 12.5 Index Implementations w ith Symbol Tables Section 12.6 Binary Search Trees Section 12.7 Performance Characteristics of BSTs Section 12.8 Insertion at the Root in BSTs Section 12.9 BST Implementations of Other ADT Operations Chapter 13 Balanced Trees Exercises Section 13.1 Randomized BSTs Section 13.2 Splay BSTs Section 13.3 Top-Dow n 2-3-4 Trees Section 13.4 Red–Black Trees Section 13.5 Skip Lists Section 13.6 Performance Characteristics Chapter 14 Hashing Section 14.1 Hash Functions Section 14.2 Separate Chaining Section 14.3 Linear Probing Section 14.4 Double Hashing Section 14.5 Dynamic Hash Tables Section 14.6 Perspective Chapter 15 Radix Search Section 15.1 Digital Search Trees Section 15.2 Tries Section 15.3 Patricia Tries Section 15.4 Multiw ay Tries and TSTs Section 15.5 Text-String–Index Algorithms Chapter 16 External Searching Section 16.1 Rules of the Game Section 16.2 Indexed Sequential Access Section 16.3 B Trees Section 16.3 B Trees Section 16.4 Extendible Hashing Section 16.5 Perspective References for Part Four Appendix Exercises Top Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks W here those designations appear in this book and Addison-Wesley w as aw are of a trademark claim, the designations have been printed in initial capital letters or all capitals The author and publisher have taken care in the preparation of this book, but make no expressed or implied w arranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or consequential damages in connection w ith or arising out of the use of the information or programs contained herein The publisher offers discounts on this book w hen ordered in quantity for special sales For more information, please contact: U.S Corporate and Government Sales (800) 382-3410 corpsales@pearsontechgroup.com For sales outside of the United States, please contact: International Sales (317) 581-3793 international@pearsontechgroup.com Visit Addison-W esley on the W eb: w w w aw professional.com Library of Congress Cataloging-in-Publication Data Sedgew ick, Robert, 1946 – Algorithms in Java / Robert Sedgew ick — 3d ed p cm Includes bibliographical references and index Contents: v 1, pts 1–4 Fundamentals, data structures, sorting, searching Java (Computer program language) Computer algorithms I Title QA76.73.C15S 2003 005.13'3—dc20 92-901 CIP Copyright © 2003 by Pearson Education, Inc All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherw ise, w ithout the prior w ritten permission of the publisher Printed in the United States of America Published simultaneously in Canada For information on obtaining permission for use of material from this w ork, please submit a w ritten request to: Pearson Education, Inc 75 Arlington Street, Suite 300 Boston, MA 02116 Fax: (617) 848-7047 corpsales@pearsontechgroup.com Text printed on recycled paper 10 – CRS – 0605040302 First printing, July 2002 Dedication To Adam, Andrew, Brett, Robbie, and especially Linda Top Previous Section Preface This book is the first of three volumes that are intended to survey the most important computer algorithms in use today This first volume (Parts I–IV) covers fundamental concepts (Part I), data structures (Part II), sorting algorithms (Part III), and searching algorithms (Part IV); the second volume (Part 5) covers graphs and graph algorithms; and the (yet to be published) third volume (Parts 6–8) covers strings (Part 6), computational geometry (Part 7), and advanced algorithms and applications (Part 8) The books are useful as texts early in the computer science curriculum, after students have acquired basic programming skills and familiarity w ith computer systems, but before they have taken specialized courses in advanced areas of computer science or computer applications The books also are useful for self-study or as a reference for people engaged in the development of computer systems or applications programs because they contain implementations of useful algorithms and detailed information on these algorithms' performance characteristics The broad perspective taken makes the series an appropriate introduction to the field Together the three volumes comprise the Third Edition of a book that has been w idely used by students and programmers around the w orld for many years I have completely rew ritten the text for this edition, and I have added thousands of new exercises, hundreds of new figures, dozens of new programs, and detailed commentary on all the figures and programs This new material provides both coverage of new topics and fuller explanations of many of the classic algorithms A new emphasis on abstract data types throughout the books makes the programs more broadly useful and relevant in modern object-oriented programming environments People w ho have read previous editions w ill find a w ealth of new information throughout; all readers w ill find a w ealth of pedagogical material that provides effective access to essential concepts These books are not just for programmers and computer science students Everyone w ho uses a computer w ants it to run faster or to solve larger problems The algorithms that w e consider represent a body of know ledge developed during the last 50 years that is the basis for the efficient use of the computer for a broad variety of applications 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; and from database systems to Internet search engines, they have become essential parts of modern softw are systems As the scope of computer applications becomes more w idespread, so grow s the impact of basic algorithms The goal of this book is to serve as a resource so that students and professionals can know and make intelligent use of these fundamental algorithms as the need arises in w hatever computer application they might undertake Previous Section Top Previous Section Scope This book, Algorithms in Java, Third Edition, Parts 1-4, contains 16 chapters grouped into four major parts: fundamentals, data structures, sorting, and searching The descriptions here are intended to give readers an understanding of the basic properties of as broad a range of fundamental algorithms as possible The algorithms described here have found w idespread use for years, and represent an essential body of know ledge for both the practicing programmer and the computer-science student The second volume is devoted to graph algorithms, and the third consists of four additional parts that cover strings, geometry, and advanced topics My primary goal in developing these books has been to bring together fundamental methods from these areas, to provide access to the best methods know n for solving problems by computer You w ill most appreciate the material here if you have had one or tw o previous courses in computer science or have had equivalent programming experience: one course in programming in a high-level language such as Java, C, or C++, and perhaps another course that teaches fundamental concepts of programming systems This book is thus intended for anyone conversant w ith a modern programming language and w ith the basic features of modern computer systems References that might help to fill in gaps in your background are suggested in the text Most of the mathematical material supporting the analytic results is self-contained (or is labeled as beyond the scope of this book), so little specific preparation in mathematics is required for the bulk of the book, although mathematical maturity is definitely helpful Previous Section Top Previous Section Use in the Curriculum There is a great deal of flexibility in how the material here can be taught, depending on the taste of the instructor and the preparation of the students There is sufficient coverage of basic material for the book to be used to teach data structures to beginners, and there is sufficient detail and coverage of advanced material for the book to be used to teach the design and analysis of algorithms to upper-level students Some instructors may w ish to emphasize implementations and practical concerns; others may w ish to emphasize analysis and theoretical concepts An elementary course on data structures and algorithms might emphasize the basic data structures in Part II and their use in the implementations in Parts III and IV A course on design and analysis of algorithms might emphasize the fundamental material in Part I and Chapter 5, then study the w ays in w hich the algorithms in Parts III and IV achieve good asymptotic performance A course on softw are engineering might omit the mathematical and advanced algorithmic material, and emphasize how to integrate the implementations given here into large programs or systems A course on algorithms might take a survey approach and introduce concepts from all these areas Earlier editions of this book that are based on other programming languages have been used at scores of colleges and universities as a text for the second or third course in computer science and as supplemental reading for other courses At Princeton, our experience has been that the breadth of coverage of material in this book provides our majors w ith an introduction to computer science that can be expanded on in later courses on analysis of algorithms, systems programming, and theoretical computer science, w hile providing the grow ing group of students from other disciplines w ith a large set of techniques that these people can put to good use immediately The exercises—nearly all of w hich are new to this third edition—fall into several types Some are intended to test understanding of material in the text, and simply ask readers to w ork through an example or to apply concepts described in the text Others involve implementing and putting together the algorithms, or running empirical studies to compare variants of the algorithms and to learn their properties Still others are a repository for important information at a level of detail that is not appropriate for the text Reading and thinking about the exercises w ill pay dividends for every reader Previous Section Top Previous Section Algorithms of Practical Use Anyone w anting to use a computer more effectively can use this book for reference or for self-study People w ith programming experience can find information on specific topics throughout the book To a large extent, you can read the individual chapters in the book independently of the others, although, in some cases, algorithms in one chapter make use of methods from a previous chapter The orientation of the book is to study algorithms likely to be of practical use The book provides information about the tools of the trade to the point that readers can confidently implement, debug, and put algorithms to w ork to solve a problem or to provide functionality in an application Full implementations of the methods discussed are included, as are descriptions of the operations of these programs on a consistent set of examples Because w e w ork w ith real code, rather than w rite pseudo-code, you can put the programs to practical use quickly Program listings are available from the book's home page You can use these w orking programs in many w ays to help you study algorithms Read them to check your understanding of the details of an algorithm, or to see one w ay to handle initializations, boundary conditions, and other aw kw ard situations that often pose programming challenges Run them to see the algorithms in action, to study performance empirically and check your results against the tables in the book, or to try your ow n modifications Characteristics of the algorithms and of the situations in w hich they might be useful are discussed in detail Connections to the analysis of algorithms and theoretical computer science are developed in con-text W hen appropriate, empirical and analytic results are presented to illustrate w hy certain algorithms are preferred W hen interesting, the relationship of the practical algorithms being discussed to purely theoretical results is described Specific information on performance characteristics of algorithms and implementations is synthesized, encapsulated, and discussed throughout the book Previous Section Top ... 10 00 3 819 63 53 17 18 15 2500 12 263 18 5 15 9 22 19 24 5000 215 91 698 697 34 33 35 10 000 41 1 40 28 91 3987 85 10 1 74 25000 16 2 748 237 267 267 50000 279279 44 7 533 47 3 10 0000 67 611 3 13 82 12 38 11 74. .. Hashing Section 14 .1 Hash Functions Section 14 .2 Separate Chaining Section 14 .3 Linear Probing Section 14 .4 Double Hashing Section 14 .5 Dynamic Hash Tables Section 14 .6 Perspective Chapter 15 Radix... main(String[] args) { int N = Integer.parseInt(args[0]); int id[] = new int[N]; for (int i = 0; i < N ; i++) id[i] = i; for( In. init(); !In. empty(); ) { int p = In. getInt(), q = In. getInt(); int

Ngày đăng: 26/03/2019, 16:28

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan