100%(1)100% found this document useful (1 vote) 598 views929 pagesEDA - Weiss - Data Structures and Problem Solving Using Java
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Data Structures &
f Problem Solving
Using Java
mark allen weiss
florida international university
Boston San Francisco New York
Sydney Tokyo Singapore Madrid
inich Paris CapeTown Hong Kong Montreal
London
Mexico CitySenior Acquisitions Editor Michael Hirsch
Production Supervisor Marilyn Lloyd
Production and Editorial Services Gillian Hall and Juliet Silveri
Copyeditor Penelope Hull
Proofreader Holly McLean-Aldis
Marketing Manager Michelle Brown
Marketing Assistant Jake Zavracky
Cover Design Supervisor Joyce Cosentino Wells,
CoverDesign Night & Day Design
Prepress Buyer Caroline Fell
Cover Image © 2004 Photodise
Access the latest information about Addison-Wesley titles from our World Wide Web site:
hutp://www.aw-be.com/computing
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 Addison.
Wesley was aware of a trademark claim, the designations have been printed in initial caps
or all caps,
‘The programs and applications presented in this book have been included for their instruc-
tional value. They have been tested with care, but are not guaranteed for any particular
purpose. The publisher does not offer any warranties or representations, nor does it accept
any liabilities with respect to the programs or applications.
Library of Congress Cataloging-in-Publication Data
Weiss, Mark Allen.
Data structures and problem solving using Java / Mark Allen Weiss.-- 3rd ed
p.cm
Includes bibliographical references and index.
ISBN 0-321-32213-4
1. Java (Computer program language) 2. Data structures (Computer science)
3, Problem solving--Data processing. I. Title.
QA76.73.538W45 2005
005.13'3~de22
2004031048
For information on obtaining permission for use of material in this work, please submit a
written request to Pearson Education, Inc., Rights and Contracts Department, 75 Arlington
Street, Suite 300, Boston, MA 021 16 or fax your request to (617) 848-7047.
Copyright © 2006 by Pearson Education, Inc.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval
syst ransmitted, in any form or by any means, electronic, mechanical, photocopy
ing, recording, or otherwise, without the prior written permission of the publisher. Printed
in the United States of America,
12345678910- HT-070605To the love of my life, Jill.preface
T.. book is designed for a two-semester sequence in computer science,
beginning with what is typically known as Data Structures and continuing
with advanced data structures and algorithm analysis. It is appropriate for the
courses from both the two-course and three-course sequences in “B.1 Intro-
ductory Tracks,” as outlined in the final report of the Computing Curricula
2001 project (CC2001)—a joint undertaking of the ACM and the IEEE.
The content of the Data Structures course has been evolving for some
time, Although there is some general consensus concerning topic coverage,
considerable disagreement still exists over the details. One uniformly
accepted topic is principles of software development, most notably the con-
cepts of encapsulation and information hiding. Algorithmically, all Data
Structures courses tend to include an introduction to running-time anal;
recursion, basic sorting algorithms, and elementary data structures. Many uni-
versities offer an advanced course that covers topics in data structures, algo-
rithms, and running-time analysis at a higher level. The material in this text
has been designed for use in both levels of courses, thus eliminating the need
to purchase a second textbook.
Although the most passionate debates in Data Structures revolve around
the choice of a programming language, other fundamental choices need to be
made:
Whether to introduce object-oriented design or object-based
design early
= The level of mathematical rigorpreface
The appropriate balance between the implementation of data struc-
tures and their use
Programming details related to the language chosen (for instance,
should GUIs be used early)
My goal in writing this text was to provide a practical introduction to data
structures and algorithms from the viewpoint of abstract thinking and prob-
lem solving. I tried to cover all the important details concerning the data
structures, their analyses, and their Java implementations, while staying away
from data structures that are theoretically interesting but not widely used. It is
impossible to cover all the different data structures, including their uses and
the analysis, described in this text in a single course. So I designed the text-
book to allow instructors flexibility in topic coverage. The instructor will need
to decide on an appropriate balance between practice and theory and then
choose the topics that best fit the course. As I discuss later in this Preface, I
organized the text to minimize dependencies among the various chapters.
a unique approach
My basic premise is that software development tools in all languages come
with large libraries, and many data structures are part of these libraries. I
envision an eventual shift in emphasis of data structures courses from
implementation to use. In this book I take a unique approach by separating
the data structures into their specification and subsequent implementation
and taking advantage of an already existing data structures library, the Java
Collections API.
A subset of the Collections API suitable for most applications is discussed
ina single chapter (Chapter 6) in Part Two. Part Two also covers basic analy-
sis techniques, recursion, and sorting. Part Three contains a host of applica-
tions that use the Collections API's data structures. Implementation of the
Collections API is not shown until Part Four, once the data structures have
already been used. Because the Collections API is part of Java students can
design large projects early on, using existing software components.
Despite the central use of the Collections API in this text, it is neither a
book on the Collections API nor a primer on implementing the Collections
API specifically; it remains a book that emphasizes data structures and basic
problem-solving techniques. Of course, the general techniques used in the
design of data structures are applicable to the implementation of the Collec-
tions API, so several chapters in Part Four include Collections API implemen-tations, However, instructors can choose the simpler implementations in Part
Four that do not discuss the Collections API protocol. Chapter 6, which pre-
sents the Collections API, is essential to understanding the code in Part Three.
attempted to use only the basic parts of the Collections API.
Many instructors will prefer a more traditional approach in which each
data structure is defined, implemented, and then used. Because there is no
dependency between material in Parts Three and Four, a traditional course can
easily be taught from this book
prerequisites
Students using this book should have knowledge of either an object-oriented
or procedural programming language. Knowledge of basic features, including
primitive data types, operators, control structures, functions (methods), and
input and output (but not necessarily arrays and classes) is assumed.
Students who have taken a first course using C-++ or Java may find the first
four chapters “light” reading in some places. However, other parts are definitely
“heavy” with Java details that may not have been covered in introductory courses.
Students who have had a first course in another language should begin at
Chapter 1 and proceed slowly. If a student would like to use a Java reference
book as well, some recommendations are given in Chapter 1, pages 3-25
Knowledge of discrete math is helpful but is not an absolute prerequisite.
Several mathematical proofs are presented, but the more complex proofs are
preceded by a brief math review. Chapters 7 and 19-24 require some degree
of mathematical sophistication, The instructor may easily elect to skip mathe-
matical aspects of the proofs by presenting only the results. All proofs in the
text are clearly marked and are separate from the body of the text.
summary of changes in
the third edition
1. The code was completely rewritten to use generics, which were
introduced in Java 5. The code also makes significant use of the
enhanced for loop and autoboxing.
2. In Java 5, the priority queue is now part of the standard Collections
API. This change is reflected in the discussion in Chapter 21 and in
some of the code in Part Three.
preface