(eBook PDF) Data Structures and Abstractions with Java 4th Edition pdf download
(eBook PDF) Data Structures and Abstractions with Java 4th Edition pdf download
https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-edition/
https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-global-edition/
ebookluna.com
https://ebookluna.com/product/data-structures-and-abstractions-with-
java-5th-edition-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-5th-edition-by-frank-m-carrano/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-4th-edition/
ebookluna.com
(eBook PDF) Data Structures and Other Objects Using Java
4th Edition
https://ebookluna.com/product/ebook-pdf-data-structures-and-other-
objects-using-java-4th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-data-structures-and-problem-
solving-using-java-4th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-introduction-to-java-
programming-and-data-structures-comprehensive-version-11/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-java-foundations-introduction-
to-program-design-and-data-structures-5th-edition/
ebookluna.com
●● Chapters 10 and 11 use exceptions in the specification and implementations of the ADTs queue, deque,
New to this Edition
and priority queue.
●● Chapter 11 no longer covers the vector-based implementation of the ADT queue; it is left as a program-
ming project.
●● Chapters 12, 13, and 14 use exceptions in the specification and implementations of the ADT list.
●● Chapter 13 changes the array-based implementation of the ADT list by ignoring the array element at
index 0. The vector-based implementation of the ADT list is no longer covered, but is left as a program-
ming project.
●● Chapter 15 covers only iterators for the ADT list. The concepts of an iterator in Java are treated in the
preceding Java Interlude 5 instead of in this chapter.
●● Chapter 20 no longer covers the vector-based implementation of the ADT dictionary; it is left as a
programming project.
●● Chapter 23 defines balanced binary trees, which previously was in Chapter 25.
●● Chapter 24 no longer defines an interface for a binary node, and the class BinaryNode no longer
implements one.
vi
The topics that we cover in this book deal with the various ways of organizing data so that a given
A Note to Students
application can access and manipulate data in an efficient way. These topics are fundamental to your future
study of computer science, as they provide you with the foundation of knowledge required to create com-
plex and reliable software. Whether you are interested in designing video games or software for robotic
controlled surgery, the study of data structures is vital to your success. Even if you do not study all of the
topics in this book now, you are likely to encounter them later. We hope that you will enjoy reading the
book, and that it will serve as a useful reference tool for your future courses.
After looking over this preface, you should read the Introduction. There you will quickly see what this
book is about and what you need to know about Java before you begin. The Prelude discusses class design
and the use of Java interfaces. We use interfaces throughout the book. Appendixes A through E review
javadoc comments, Java basics, classes, inheritance, and files. New Java Interludes occur throughout the
book and cover advanced aspects of Java as they are needed. Note that inside the front and back covers
you will find Java’s reserved words, its primitive data types, the precedence of its operators, and a list of
Unicode characters.
Please be sure to browse the rest of this preface to see the features that will help you in your studies.
vii
Features to Enhance Learning
Pedagogical Elements
Each chapter begins with a table of contents, a list of prerequisite portions of the book that you should
have read, and the learning objectives for the material to be covered. Other pedagogical elements appear
throughout the book, as follows:
Notes Important ideas are presented or summarized in highlighted paragraphs and are meant
to be read in line with the surrounding text.
VideoNote
Security Notes Aspects of safe and secure programming are introduced and h ighlighted in
this new feature.
VideoNote
A Problem Solved Large examples are presented in the form of “A Problem Solved,” in which
a problem is posed and its solution is discussed, designed, and implemented.
Design Decisions To give readers insight into the design choices that one could make when
formulating a solution, “Design Decision” elements lay out such options, along with the
VideoNote rationale behind the choice made for a particular example. These discussions are often in the
context of one of the “A Problem Solved” examples.
Self-Test Questions Questions are posed throughout each chapter, integrated within the text,
that reinforce the concept just presented. These “self-test” questions help readers to understand
the material,
VideoNotesince answering them requires pause and reflection. Solutions to these questions
VideoNotes Online tutorials are a Pearson feature that provides visual and audio support to
the presentation given throughout the book. They offer students another way to recap and
VideoNote reinforce key concepts. VideoNotes allow for self-paced instruction with easy navigation,
including the ability to select, play, rewind, fast-forward, and stop within each video. Unique
VideoNote icons appear throughout this book whenever a video is available for a particular
concept or problem. A detailed list of the VideoNotes for this text and their associated loca-
tions in the book can be found on page xxvi. VideoNotes are free with the purchase of a new
textbook. To purchase access to VideoNotes, please go to
pearsonhighered.com/carrano
Exercises and Programming Projects Further practice is available by solving the exercises
and programming projects at the end of each chapter. Unfortunately, we cannot give readers the
answers to these exercises and programming projects, even if they are not enrolled in a class.
Only instructors who adopt the book can receive selected answers from the publisher. For help
with these exercises and projects, you will have to contact your instructor.
viii
Accessing Instructor and Student Resource Materials
Resources
The following items are available on the publisher’s website at pearsonhighered.com/carrano:
Instructor Resources
T he following protected material is available to instructors who adopt this book by logging onto Pearson’s
Instructor Resource Center, accessible from pearsonhighered.com/carrano:
●● PowerPoint lecture slides
●● Solutions to exercises and projects
●● Test bank
●● Instructor source code
●● Figures from the book
Additionally, instructors can access the book’s Companion Website for the following online premium
content, also accessible from pearsonhighered.com/carrano:
●● Instructional VideoNotes
●● Appendixes B, C, and E
●● A glossary of terms
Please contact your Pearson sales representative for an instructor access code. Contact information is avail-
able at pearsonhighered.com/replocator.
Student Resources
The following material is available to students by logging onto the Companion Website accessible from
pearsonhighered.com/carrano:
●● Instructional VideoNotes
●● Appendixes B, C, and E
●● A glossary of terms
Students must use the access card located in the front of the book to register for and then enter the Com-
panion Website. Students without an access code can purchase access from the Companion Website by
following the instructions listed there.
Note that the Java Class Library is available at docs.oracle.com/javase/8/docs/api/.
ix
Content Overview
Detailed Content Description
Readers of this book should have completed a programming course, preferably in Java. The appendixes
cover the essentials of Java that we assume readers will know. You can use these appendixes as a review or
as the basis for making the transition to Java from another programming language. The book itself begins
with the Introduction, which sets the stage for the data organizations that we will study.
●● Prelude: At the request of readers of the previous edition, we have moved the introduction to class
design from the appendix to the beginning of the book. Most of the material that was in Appendix D of
the third edition is now in the Prelude, which follows the Introduction.
●● Chapters 1 through 3: We introduce the bag as an abstract data type (ADT). By dividing the mate-
rial across several chapters, we clearly separate the specification, use, and implementation of the bag.
For example, Chapter 1 specifies the bag and provides several examples of its use. This chapter also
introduces the ADT set. Chapter 2 covers implementations that use arrays, while Chapter 3 introduces
chains of linked nodes and uses one in the definition of a class of bags.
In a similar fashion, we separate specification from implementation throughout the book when
we discuss various other ADTs. You can choose to cover the chapters that specify and use the ADTs
and then later cover the chapters that implement them. Or you can cover the chapters as they appear,
implementing each ADT right after studying its specification and use. A list of chapter prerequisites
appears later in this preface to help you plan your path through the book.
Chapter 2 does more than simply implement the ADT bag. It shows how to approach the imple-
mentation of a class by initially focusing on core methods. When defining a class, it is often useful
to implement and test these core methods first and to leave definitions of the other methods for later.
Chapter 2 also introduces the concept of safe and secure programming, and shows how to add this
protection to your code.
●● Java Interludes 1 and 2: The first Java interlude introduces generics, so that we can use it with our
first ADT, the bag. This interlude immediately follows Chapter 1. Java Interlude 2 introduces excep-
tions and follows Chapter 2. We apply this material, which was formerly in an appendix, to the imple-
mentations of the ADT bag.
●● Chapter 4: Here we introduce the complexity of algorithms, a topic that we integrate into future
chapters.
●● Chapters 5 and 6: Chapter 5 discusses stacks, giving examples of their use, and Chapter 6 implements
the stack using an array, a vector, and a chain.
●● Chapter 7: Next, we present recursion as a problem-solving tool and its relationship to stacks.
Recursion, along with algorithm efficiency, is a topic that is revisited throughout the book.
●● Java Interlude 3: This interlude provides the Java concepts needed for the sorting methods that we
are about to present. It introduces the standard interface Comparable, generic methods, bounded type
parameters, and wildcards.
●● Chapters 8 and 9: The next two chapters discuss various sorting techniques and their relative com-
plexities. We consider both iterative and recursive versions of these algorithms.
●● Java Interlude 4: This Java interlude shows how the programmer can write new exception classes. In
doing so, it shows how to extend an existing class of exceptions. It also introduces the finally block.
●● Chapters 10 and 11: Chapter 10 discusses queues, deques, and priority queues, and Chapter 11 con-
siders their implementations. It is in this latter chapter that we introduce circularly linked and doubly
linked chains. Chapter 11 also uses the programmer-defined class EmptyQueueException.
●● Chapters 12, 13, and 14: The next three chapters introduce the ADT list. We discuss this collection
abstractly and then implement it by using an array and a chain of linked nodes.
●● Java Interlude 5 and Chapter 15: The coverage of Java iterators that was formerly in Chapter 15
now appears before the chapter in Java Interlude 5. Included are the standard interfaces Iterator,
x
Iterable, and ListIterator. Chapter 15 then shows ways to implement an iterator for the ADT list.
xi
Acknowledgments
Acknowledgments
Our sincere appreciation and thanks go to the following reviewers for carefully reading the previous edi-
tion and making candid comments and suggestions that greatly improved the work:
xii
Henry Etlinger—Rochester Institute of Technology
Acknowledgments
Derek Harter—Texas A&M University
Timothy Henry—New England Institute of Technology
Robert Holloway—University of Wisconsin, Madison
Charles Hoot—Oklahoma City University
Teresa Leyk—Texas A&M University
Robert McGlinn—Southern Illinois University, Carbondale
Edward Medvid—Marymount University
Charles Metzler—City College of San Francisco
Daniel Zeng—University of Arizona
Reviewers for the first edition:
David Boyd—Valdosta State University
Dennis Brylow—Purdue University
Michael Croswell—Industry trainer/consultant
Matthew Dickerson—Middlebury College
Robert Holloway—University of Wisconsin, Madison
John Motil—California State University, Northridge
Bina Ramamurthy—University at Buffalo, SUNY
David Surma—Valparaiso University
We continue to appreciate the many others who helped during previous editions. They include Alan
Apt, James Blanding, Lianne Dunn, Mike Giacobbe, Toni Holm, Charles Hoot, Brian Jepson, Rose Kernan,
Christianna Lee, Patrick Lindner, John Lovell, Vince O’Brien, Patty Roy, Walt Savitch, Ben Schomp, Heather
Scott, Carole Snyder, Chirag Thakkar, Camille Trentacoste, Nate Walker, and Xiaohong Zhu.
Finally, we thank our families and friends—Doug, Joanne, Tita, Bobby, Ted, Nancy, Sue, Tom, Maybeth,
Marge, and Lorraine—for giving us lives away from computers.
Thank you, everyone, for your expertise and good cheer.
Frank M. Carrano
Timothy M. Henry
xiii
This page intentionally left blank
Contents
Table of Contents
Introduction: Organizing Data 1
Prelude: Designing Classes 5
Encapsulation 6
Specifying Methods 8
Comments 8
Preconditions and Postconditions 9
Assertions 10
Java Interfaces 11
Writing an Interface 12
Implementing an Interface 13
An Interface as a Data Type 15
Extending an Interface 16
Named Constants Within an Interface 17
Choosing Classes 19
Identifying Classes 20
CRC Cards 21
The Unified Modeling Language 21
Reusing Classes 24
Chapter 1 Bags 31
The Bag 32
A Bag’s Behaviors 32
Specifying a Bag 33
An Interface 39
Using the ADT Bag 41
Using an ADT Is Like Using a Vending Machine 45
The ADT Set 47
Java Class Library: The Interface set 47
Java Interlude 1 Generics 53
Generic Data Types 53
Generic Types Within an Interface 54
Generic Classes 55
Chapter 2 Bag Implementations That Use Arrays 59
Using a Fixed-Size Array to Implement the ADT Bag 60
An Analogy 60
A Group of Core Methods 61
Implementing the Core Methods 62
Making the Implementation Secure 69
Testing the Core Methods 71
Implementing More Methods 73
Methods That Remove Entries 76
Using Array Resizing to Implement the ADT Bag 84
Resizing an Array 84
A New Implementation of a Bag 87
The Pros and Cons of Using an Array to Implement the ADT Bag 90
xv
Java Interlude 2 Exceptions 95
Table of Contents
The Basics 96
Handling an Exception 98
Postpone Handling: The throws Clause 98
Handle It Now: The try-catch Blocks 99
Multiple catch Blocks 100
Throwing an Exception 101
Chapter 3 A Bag Implementation That Links Data 103
Linked Data 104
Forming a Chain by Adding to Its Beginning 105
A Linked Implementation of the ADT Bag 107
The Private Class Node 107
An Outline of the Class LinkedBag 108
Defining Some Core Methods 109
Testing the Core Methods 113
The Method getFrequencyOf114
The Method contains115
Removing an Item from a Linked Chain 116
The Methods remove and clear117
A Class Node That Has Set and Get Methods 121
The Pros and Cons of Using a Chain to Implement the ADT Bag 124
Chapter 4 The Efficiency of Algorithms 129
Motivation 130
Measuring an Algorithm’s Efficiency 131
Counting Basic Operations 133
Best, Worst, and Average Cases 135
Big Oh Notation 136
The Complexities of Program Constructs 138
Picturing Efficiency 140
The Efficiency of Implementations of the ADT Bag 143
An Array-Based Implementation 143
A Linked Implementation 145
Comparing the Implementations 146
Chapter 5 Stacks 153
Specifications of the ADT Stack 154
Using a Stack to Process Algebraic Expressions 158
A Problem Solved: Checking for Balanced Delimiters in an
Infix Algebraic Expression 159
A Problem Solved: Transforming an Infix Expression
to a Postfix Expression 164
A Problem Solved: Evaluating Postfix Expressions 169
A Problem Solved: Evaluating Infix Expressions 171
The Program Stack 173
Java Class Library: The Class Stack174
Chapter 6 Stack Implementations 181
A Linked Implementation 181
An Array-Based Implementation 185
xvi
A Vector-Based Implementation 189
Table of Contents
Java Class Library: The Class Vector 190
Using a Vector to Implement the ADT Stack 190
Chapter 7 Recursion 197
What Is Recursion? 198
Tracing a Recursive Method 202
Recursive Methods That Return a Value 205
Recursively Processing an Array 207
Recursively Processing a Linked Chain 210
The Time Efficiency of Recursive Methods 211
The Time Efficiency of countDown 212
The Time Efficiency of Computing xn 213
A Simple Solution to a Difficult Problem 214
A Poor Solution to a Simple Problem 219
Tail Recursion 221
Indirect Recursion 223
Using a Stack Instead of Recursion 224
Java Interlude 3 More About Generics 235
The Interface Comparable 235
Generic Methods 237
Bounded Type Parameters 238
Wildcards 240
Bounded Wildcards 241
Chapter 8 An Introduction to Sorting 245
Organizing Java Methods That Sort an Array 246
Selection Sort 247
Iterative Selection Sort 248
Recursive Selection Sort 250
The Efficiency of Selection Sort 251
Insertion Sort 251
Iterative Insertion Sort 253
Recursive Insertion Sort 255
The Efficiency of Insertion Sort 257
Insertion Sort of a Chain of Linked Nodes 257
Shell Sort 260
The Algorithm 262
The Efficiency of Shell Sort 263
Comparing the Algorithms 263
Chapter 9 Faster Sorting Methods 271
Merge Sort 272
Merging Arrays 272
Recursive Merge Sort 273
The Efficiency of Merge Sort 275
Iterative Merge Sort 277
Merge Sort in the Java Class Library 277
Quick Sort 278
The Efficiency of Quick Sort 278
Creating the Partition 279
xvii
Implementing Quick Sort 282
Table of Contents
Quick Sort in the Java Class Library 284
Radix Sort 284
Pseudocode for Radix Sort 285
The Efficiency of Radix Sort 286
Comparing the Algorithms 286
Java Interlude 4 More About Exceptions 293
Programmer-Defined Exception Classes 293
Inheritance and Exceptions 297
The finally Block 298
Chapter 10 Queues, Deques, and Priority Queues 301
The ADT Queue 302
A Problem Solved: Simulating a Waiting Line 306
A Problem Solved: Computing the Capital Gain in a Sale of Stock 312
Java Class Library: The Interface Queue 315
The ADT Deque 316
A Problem Solved: Computing the Capital Gain in a Sale of Stock 319
Java Class Library: The Interface Deque 320
Java Class Library: The Class ArrayDeque 321
The ADT Priority Queue 321
A Problem Solved: Tracking Your Assignments 323
Java Class Library: The Class PriorityQueue 325
Chapter 11 Queue, Deque, and Priority Queue Implementations 331
A Linked Implementation of a Queue 332
An Array-Based Implementation of a Queue 336
A Circular Array 336
A Circular Array with One Unused Location 339
Circular Linked Implementations of a Queue 344
A Two-Part Circular Linked Chain 345
Java Class Library: The Class AbstractQueue 350
A Doubly Linked Implementation of a Deque 351
Possible Implementations of a Priority Queue 355
Chapter 12 Lists 361
Specifications for the ADT List 362
Using the ADT List 369
Java Class Library: The Interface List 373
Java Class Library: The Class ArrayList 373
Chapter 13 A List Implementation That Uses an Array 379
Using an Array to Implement the ADT List 380
An Analogy 380
The Java Implementation 382
The Efficiency of Using an Array to Implement the ADT List 390
Chapter 14 A List Implementation That Links Data 397
Operations on a Chain of Linked Nodes 398
Adding a Node at Various Positions 398
Removing a Node from Various Positions 402
The Private Method getNodeAt 403
xviii
Beginning the Implementation 404
Table of Contents
The Data Fields and Constructor 405
Adding to the End of the List 407
Adding at a Given Position Within the List 408
The Methods isEmpty and toArray 409
Testing the Core Methods 411
Continuing the Implementation 412
A Refined Implementation 415
The Tail Reference 415
The Efficiency of Using a Chain to Implement the ADT List 418
Java Class Library: The Class LinkedList 420
Java Interlude 5 Iterators 427
What Is an Iterator? 427
The Interface Iterator 429
The Interface Iterable 431
Using the Interface Iterator 431
Iterable and for-each Loops 435
The Interface ListIterator 436
The Interface List Revisited 439
Using the Interface ListIterator 440
Chapter 15 Iterators for the ADT List 443
Ways to Implement an Iterator 444
A Separate Class Iterator 444
An Inner Class Iterator 447
A Linked Implementation 448
An Array-Based Implementation 451
Why Are Iterator Methods in Their Own Class? 454
An Array-Based Implementation of the Interface ListIterator 456
The Inner Class 457
Java Interlude 6 Mutable and Immutable Objects 469
Mutable Objects 470
Immutable Objects 472
Creating a Read-Only Class 472
Companion Classes 474
Chapter 16 Sorted Lists 477
Specifications for the ADT Sorted List 478
Using the ADT Sorted List 481
A Linked Implementation 482
The Method add 483
The Efficiency of the Linked Implementation 490
An Implementation That Uses the ADT List 490
Efficiency Issues 493
Java Interlude 7 Inheritance and Polymorphism 499
Further Aspects of Inheritance 499
When to Use Inheritance 499
Protected Access 500
Abstract Classes and Methods 501
Interfaces Versus Abstract Classes 503
Polymorphism 504
xix
Chapter 17 Inheritance and Lists 511
Table of Contents
Using Inheritance to Implement a Sorted List 512
Designing a Base Class 514
Creating an Abstract Base Class 519
An Efficient Implementation of a Sorted List 521
The Method add 521
Chapter 18 Searching 527
The Problem 528
Searching an Unsorted Array 528
An Iterative Sequential Search of an Unsorted Array 529
A Recursive Sequential Search of an Unsorted Array 530
The Efficiency of a Sequential Search of an Array 532
Searching a Sorted Array 532
A Sequential Search of a Sorted Array 532
A Binary Search of a Sorted Array 533
Java Class Library: The Method binarySearch 538
The Efficiency of a Binary Search of an Array 538
Searching an Unsorted Chain 539
An Iterative Sequential Search of an Unsorted Chain 540
A Recursive Sequential Search of an Unsorted Chain 540
The Efficiency of a Sequential Search of a Chain 541
Searching a Sorted Chain 541
A Sequential Search of a Sorted Chain 541
A Binary Search of a Sorted Chain 542
Choosing a Search Method 542
Java Interlude 8 Generics Once Again 549
More Than One Generic Type 549
Chapter 19 Dictionaries 551
Specifications for the ADT Dictionary 552
A Java Interface 556
Iterators 557
Using the ADT Dictionary 558
A Problem Solved: A Directory of Telephone Numbers 559
A Problem Solved: The Frequency of Words 564
A Problem Solved: A Concordance of Words 567
Java Class Library: The Interface Map 570
Chapter 20 Dictionary Implementations 575
Array-Based Implementations 576
An Unsorted Array-Based Dictionary 576
A Sorted Array-Based Dictionary 581
Linked Implementations 586
An Unsorted Linked Dictionary 587
A Sorted Linked Dictionary 588
Chapter 21 Introducing Hashing 595
What Is Hashing? 596
Hash Functions 599
Computing Hash Codes 599
Compressing a Hash Code into an Index for the Hash Table 602
xx
Resolving Collisions 603
Table of Contents
Open Addressing with Linear Probing 603
Open Addressing with Quadratic Probing 608
Open Addressing with Double Hashing 609
A Potential Problem with Open Addressing 611
Separate Chaining 612
Chapter 22 Hashing as a Dictionary Implementation 619
The Efficiency of Hashing 620
The Load Factor 620
The Cost of Open Addressing 621
The Cost of Separate Chaining 623
Rehashing 624
Comparing Schemes for Collision Resolution 625
A Dictionary Implementation That Uses Hashing 626
Entries in the Hash Table 626
Data Fields and Constructors 627
The Methods getValue, remove, and add 629
Iterators 634
Java Class Library: The Class HashMap 635
Jave Class Library: The Class HashSet 636
Chapter 23 Trees 639
Tree Concepts 640
Hierarchical Organizations 640
Tree Terminology 642
Traversals of a Tree 646
Traversals of a Binary Tree 647
Traversals of a General Tree 649
Java Interfaces for Trees 650
Interfaces for All Trees 650
An Interface for Binary Trees 651
Examples of Binary Trees 652
Expression Trees 653
Decision Trees 654
Binary Search Trees 658
Heaps 660
Examples of General Trees 663
Parse Trees 663
Game Trees 663
Chapter 24 Tree Implementations 673
The Nodes in a Binary Tree 674
A Class of Binary Nodes 675
An Implementation of the ADT Binary Tree 676
Creating a Basic Binary Tree 677
The Method privateSetTree 678
Accessor and Mutator Methods 681
Computing the Height and Counting Nodes 681
Traversals 682
An Implementation of an Expression Tree 687
xxi
General Trees 688
Table of Contents
A Node for a General Tree 688
Using a Binary Tree to Represent a General Tree 689
Java Interlude 9 Cloning 697
Cloneable Objects 697
Cloning an Array 703
Cloning a Chain 706
A Sorted List of Clones 709
Cloning a Binary Node 711
Chapter 25 A Binary Search Tree Implementation 713
Getting Started 714
An Interface for the Binary Search Tree 715
Duplicate Entries 717
Beginning the Class Definition 718
Searching and Retrieving 719
Traversing 720
Adding an Entry 721
A Recursive Implementation 722
An Iterative Implementation 725
Removing an Entry 726
Removing an Entry Whose Node Is a Leaf 727
Removing an Entry Whose Node Has One Child 727
Removing an Entry Whose Node Has Two Children 728
Removing an Entry in the Root 731
A Recursive Implementation 732
An Iterative Implementation 735
The Efficiency of Operations 739
The Importance of Balance 740
The Order in Which Nodes Are Added 740
An Implementation of the ADT Dictionary 740
Chapter 26 A Heap Implementation 753
Reprise: The ADT Heap 754
Using an Array to Represent a Heap 754
Adding an Entry 757
Removing the Root 760
Creating a Heap 763
Heap Sort 766
Chapter 27 Balanced Search Trees 775
AVL Trees 776
Single Rotations 776
Double Rotations 779
Implementation Details 783
2-3 Trees 787
Searching a 2-3 Tree 788
Adding Entries to a 2-3 Tree 789
Splitting Nodes During Addition 791
2-4 Trees 792
Adding Entries to a 2-4 Tree 793
Comparing AVL, 2-3, and 2-4 Trees 795
xxii
Red-Black Trees 796
Table of Contents
Properties of a Red-Black Tree 797
Adding Entries to a Red-Black Tree 798
Java Class Library: The Class TreeMap 804
B-Trees 804
Chapter 28 Graphs 811
Some Examples and Terminology 812
Road Maps 812
Airline Routes 815
Mazes 815
Course Prerequisites 816
Trees 816
Traversals 817
Breadth-First Traversal 818
Depth-First Traversal 819
Topological Order 821
Paths 824
Finding a Path 824
The Shortest Path in an Unweighted Graph 824
The Shortest Path in a Weighted Graph 827
Java Interfaces for the ADT Graph 830
Chapter 29 Graph Implementations 841
An Overview of Two Implementations 842
The Adjacency Matrix 842
The Adjacency List 843
Vertices and Edges 844
Specifying the Class Vertex 845
The Inner Class Edge 847
Implementing the Class Vertex 848
An Implementation of the ADT Graph 851
Basic Operations 851
Graph Algorithms 854
Appendix A Documentation and Programming Style 861
Naming Variables and Classes 861
Indenting 862
Comments 862
Single-Line Comments 863
Comment Blocks 863
When to Write Comments 863
Java Documentation Comments 863
Appendix B Java Basics (online)
Introduction
Applications and Applets
Objects and Classes
A First Java Application Program
Elements of Java
Identifiers
Reserved Words
Variables
xxiii
Other documents randomly have
different content
the purpose of restoring suspended animation,—while the
highwayman still looked on with a kind of mechanical attention.
At length Georgiana opened her eyes slowly; but the moment they
caught a glimpse of Lord Ellingham's countenance, a faint cry
escaped her lips—and she covered her face with her hands as if to
shut out some terrible object from her view.
"Georgiana, dearest—'tis I," murmured Arthur in her ear.
But a dreadful shudder seemed to convulse her entire frame.
"Some one has terrified her—alarmed her!" exclaimed the Earl,
colouring with anger; and as he glanced rapidly around, his eyes
met those of the highwayman.
At that moment Dr. Lascelles desired that Lady Hatfield should be
supported to her own chamber; and this suggestion was
immediately followed by the female friends and servants, the
physician accompanying them.
CHAPTER XLIII.
LORD ELLINGHAM AND TOM RAINFORD.