ebook img

Java Collections_ An Introduction to Abstract D.. PDF

566 Pages·2008·15.45 MB·English
by  
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 Java Collections_ An Introduction to Abstract D..

Java Collections This page intentionally left blank Java Collections An Introduction to Abstract Data Types, Data Structures and Algorithms David A. Watt University of Glasgow Deryck F. Brown The Robert Gordon University JOHN WILEY & SONS, LTD CHICHESTER • NEW YORK • WEINHEIM • BRISBANE • SINGAPORE • TORONTO Copyright © 2001 by John Wiley & Sons, Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England Telephone (+44) 1243 779777 Email (for orders and customer service enquiries): [email protected] Visit our Home Page www.wileyeurope.com or www.wiley.com Reprinted August 2001, July 2003 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, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London WIT 4LP, UK, without the permission in writing of the Publisher, with the exception of any material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the publication. Neither the authors) nor John Wiley & Sons, Ltd accept any responsibility or liability for loss or damage occasioned to any person or property through using the material, instructions, methods or ideas contained herein, or acting or refraining from acting as a result of such use. The authors) and Publisher expressly disclaim all implied warranties, including merchantability of fitness for any particular purpose. Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons Ltd is aware of a claim, the product names appear in initial capital or capital letters. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. Other Wiley Editorial Offices John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA Jossey-Bass, 989 Market Street, San Francisco, CA 94103–1741, USA Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany John Wiley & Sons Australia Ltd, 33 Park Road, Milton, Queensland 4064, Australia John Wiley & Sons (Asia) Pte Ltd, 2 dementi Loop #02-01, Jin Xing Distripark, Singapore 129809 John Wiley & Sons (Canada) Ltd, 22 Worcester Road, Etobicoke, Ontario M9W 1L1 Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. • British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library ISBN 0471 89978 X Cover Image — Fondaco dei Turchi, Venice (w/c) by John Ruskin (1819–1900) Ruskin Museum, Coniston, Cumbria, UK/Bridgeman Art Library Printed and bound in Great Britain by Biddies Ltd, Guildford and King's Lynn This book is printed on acid-free paper responsibly manufactured from sustainable forestry in which at least two trees are planted for each one used for paper production. Contents Preface xi 1 Introduction i I. I Historical background I 1.2 Algorithms and programs 6 1.3 Abstract data types and data structures 7 Summary 9 Exercises 9 2 Algorithms 11 2.1 Principles of algorithms 1 I 2.2 Efficiency of algorithms ) 4 2.3 Complexity of algorithms i 7 2.4 Recursive algorithms 24 Summary 31 Exercises 3 i 3 The Array Data Structure 34 3.1 Arrays 34 3.2 Insertion 38 3.3 Deletion 39 3.4 Searching 40 3.5 Merging 46 3.6 Sorting 49 Summary 62 Exercises 62 4 Linked-List Data Structures 67 4.1 Linked lists 67 4.2 Insertion 78 vi Contents 4.3 Deletion 81 4.4 Searching 86 4.5 Merging 88 4.6 Sorting 91 Summary 94 Exercises 95 5 Abstract Data Types 97 5.1 Datatypes 97 5.2 Abstract data types 103 5.3 Abstract data type design 111 5.4 String abstract data types 114 5.5 Collection abstract data types 120 5.6 Abstract data types in the Java class library 120 Summary 122 Exercises 123 6 Stack Abstract Data Types 125 6.1 The concept of a stack 125 6.2 Applications of stacks 125 6.3 A stack abstract data type 129 6.4 Implementation of bounded stacks using arrays I 30 6.5 Implementation of unbounded stacks using linked lists 132 6.6 Case study: solving and generating mazes 135 Summary 146 Exercises 146 7 Queue Abstract Data Types 149 7.1 The concept of a queue 149 7.2 Applications of queues 149 7.3 A queue abstract data type 151 7.4 Implementation of bounded queues using arrays 152 7.5 Implementation of unbounded queues using linked lists 156 7.6 Case study: a traffic simulator 157 Summary 166 Exercises 167 8 List Abstract Data Types 170 8.1 The concept of a list 170 8.2 Applications of lists 171 8.3 A list abstract data type 172 8.4 Iterators 175 8.5 Implementation of bounded lists using arrays 179 8.6 Implementation of unbounded lists using linked lists 185 8.7 Lists in the Java class library 191 8.8 Case study: a videotape manager Summary Exercises 9 Set Abstract Data Types 9.1 The concept of a set 9.2 Applications of sets 9.3 A set abstract data type 9.4 Implementation of bounded sets using arrays 9.5 Implementation of unbounded sets using linked lists 9.6 Implementation of small-integer sets using boolean arrays 9.7 Sets in the Java class library 9.8 Case study: an interactive spell-checker Summary Exercises 10 Binary Tree Data Structures 236 10.1 Binary trees 236 10.2 Searching 242 10.3 Insertion 245 10.4 Deletion 247 10.5 Traversal 256 10.6 Merging 26! 10.7 Implementation of unbounded sets using binary search trees 262 Summary 270 Exercises 270 11 Map Abstract Data Types 274 11.1 The concept of a map 274 11.2 Applications of maps 276 I11.3 A map abstract data type 277 I 1.4 Implementation of small-integer-key maps using key-indexed arrays 281 11.5 Implementation of bounded maps using arrays 283 11.6 Implementation of unbounded maps using linked lists 287 11.7 Implementation of unbounded maps using binary search trees 288 11.8 Maps in the Java class library 290 11.9 Case study: a student record system 293 Summary 303 Exercises 304 12 Hash-Table Data Structures 307 12.1 Hash tables 307 12.2 Closed-bucket hash tables 309 12.3 Open-bucket hash tables 316 12.4 Implementations of sets using hash tables 331 viii Contents 12.5 Implementations of maps using hash tables 332 Summary 334 Exercises 334 13 Priority-Queue Abstract Data Types 337 I 3.1 The concept of a priority queue 337 13.2 Applications of priority queues 338 13.3 A priority-queue abstract data type 339 13.4 Implementations of priority queues using linked lists 341 13.5 The heap data structure 344 13.6 Implementation of priority queues using heaps 355 I 3.7 Case study: an improved traffic simulator 355 Summary 361 Exercises 363 14 Tree Abstract Data Types 366 14.1 The concept of a tree 366 14.2 Applications of trees 367 14.3 A tree abstract data type 369 14.4 A linked implementation of trees 369 14.5 Specialized tree abstract data types 378 14.6 Case study: game playing 381 Summary 394 Exercises 395 15 Graph Abstract Data Types 397 15.1 The concept of a graph 397 15.2 Applications of graphs 399 15.3 Graph abstract data types 400 15.4 Edge-set representation of graphs 403 15.5 Adjacency-set representation of graphs 408 15.6 Adjacency-matnx representation of graphs 413 15.7 Graph traversal 415 15.8 Topological sort 420 15.9 Case study: material requirements planning 422 Summary 431 Exercises 431 16 Balanced Search Tree Data Structures 435 16.1 AVL-trees 435 16.2 B-trees 447 Summary 466 Exercises 467 17 Conclusion 469 17.1 Abstract data types and object-oriented design 469 17.2 Abstract data types as reusable software components 47! 17.3 Homogeneous and heterogeneous collections 472 i 7.4 Extending Java with parameterized classes 476 17.5 Case study: a student record system revisited 477 Summary 482 Exercises 482 A Summary of Mathematics for Algorithm Analysis 484 A.I Powers 484 A.2 Logarithms 486 A3 Series summations 487 A,4 Recurrences 488 A.5 O-notation 490 B Summary of Java 495 B.I Basics 495 B.2 Classes B.3 Interfaces B.4 Packages B.5 Exceptions B.6 Inner classes and inner interfaces C Summary of the Java Collections Framework 5) 7 C.I Collections 517 C.2 Lists 520 C.3 Sets 524 C.4 Maps 528 C.5 Orderings 533 C.6 Iterators 534 Further reading 537 Bibliographic notes 537 Bibliography 539 Index 540

Description:
Printed and bound in Great Britain by Biddies Ltd, Guildford and King's Lynn . This book has four major themes: algorithms, data structures, abstract data In other words, it adopts a practical (software engineering) approach to the.
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.