Ebooks File (Ebook PDF) Data Structures and Problem Solving Using Java 4th Edition All Chapters
Ebooks File (Ebook PDF) Data Structures and Problem Solving Using Java 4th Edition All Chapters
com
https://ebooksecure.com/product/ebook-pdf-data-
structures-and-problem-solving-using-java-4th-
edition/
https://ebooksecure.com/product/ebook-pdf-data-structures-and-other-
objects-using-java-4th-edition/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-edition/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-global-edition/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-starting-out-with-visual-
basic-7th-edition-by-tony-gaddis/
ebooksecure.com
(eBook PDF) Introductory Econometrics: A Modern Approach
7th Edition by Jeffrey
https://ebooksecure.com/product/ebook-pdf-introductory-econometrics-a-
modern-approach-7th-edition-by-jeffrey/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-strategic-management-
awareness-and-change-8th-edition/
ebooksecure.com
https://ebooksecure.com/product/ebook-pdf-chemistry-11th-edition-by-
raymond-chang/
ebooksecure.com
https://ebooksecure.com/download/immunology-serology-in-laboratory-
medicine-ebook-pdf/
ebooksecure.com
500 AP Physics 1 questions to know by test day 2nd Edition
Anaxos Inc. - eBook PDF
https://ebooksecure.com/download/500-ap-physics-1-questions-to-know-
by-test-day-ebook-pdf/
ebooksecure.com
summary of changes in the fourth edition
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 in a
single chapter (Chapter 6) in Part Two. Part Two also covers basic analysis techniques,
recursion, and sorting. Part Three contains a host of applications 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 Collections API, so several chapters in Part Four include
Collections API implementations. However, instructors can choose the simpler
implementations in Part Four that do not discuss the Collections API protocol. Chapter
6, which presents the Collections API, is essential to understanding the code in Part
Three. I 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
java
This textbook presents material using the Java programming language. Java is a
language that is often examined in comparison with C++. Java offers many benefits, and
programmers often view Java as a safer, more portable, and easier-to-use language than
C++.
The use of Java requires that some decisions be made when writing a textbook. Some
of the decisions made are as follows:
1. The minimum required compiler is Java 5. Please make sure you are using a
compiler that is Java 5-compatible.
2. GUIs are not emphasized. Although GUIs are a nice feature in Java, they seem
to be an implementation detail rather than a core Data Structures topic. We do
not use Swing in the text, but because many instructors may prefer to do so, a
brief introduction to Swing is provided in Appendix B.
3. Applets are not emphasized. Applets use GUIs. Further, the focus of the course
is on data structures, rather than language features. Instructors who would like
to discuss applets will need to supplement this text with a Java reference.
4. Inner classes are used. Inner classes are used primarily in the implementation
of the Collections API, and can be avoided by instructors who prefer to do so.
5. The concept of a pointer is discussed when reference variables are
introduced. Java does not have a pointer type. Instead, it has a reference type.
However, pointers have traditionally been an important Data Structures topic
that needs to be introduced. I illustrate the concept of pointers in other
languages when discussing reference variables.
6. Threads are not discussed. Some members of the CS community argue that
multithreaded computing should become a core topic in the introductory
programming sequence. Although it is possible that this will happen in the
future, few introductory programming courses discuss this difficult topic.
7. Some Java 5 features are not used. Including:
Static imports, not used because in my opinion it actually makes the code harder
to read.
Enumerated types, not used because there were few places to declare public
enumerated types that would be usable by clients. In the few possible places, it
did not seem to help the code’s readability.
text organization
Part One consists of four chapters that describe the basics of Java used throughout the
text. Chapter 1 describes primitive types and illustrates how to write basic programs in
Java. Chapter 2 discusses reference types and illustrates the general concept of a
pointer—even though Java does not have pointers—so that students learn this important
Data Structures topic. Several of the basic reference types (strings, arrays, files, and
Scanners) are illustrated, and the use of exceptions is discussed. Chapter 3 continues
this discussion by describing how a class is implemented. Chapter 4 illustrates the use
of inheritance in designing hierarchies (including exception classes and I/O) and
generic components. Material on design patterns, including the wrapper, adapter, and
decorator patterns can be found in Part One.
Part Two focuses on the basic algorithms and building blocks. In Chapter 5 a
complete discussion of time complexity and Big-Oh notation is provided. Binary search
is also discussed and analyzed. Chapter 6 is crucial because it covers the Collections
API and argues intuitively what the running time of the supported operations should be
for each data structure. (The implementation of these data structures, in both
Collections API-style and a simplified version, is not provided until Part Four). This
chapter also introduces the iterator pattern as well as nested, local, and anonymous
classes. Inner classes are deferred until Part Four, where they are discussed as an
implementation technique. Chapter 7 describes recursion by first introducing the notion
of proof by induction. It also discusses divide-and-conquer, dynamic programming, and
backtracking. A section describes several recursive numerical algorithms that are used
to implement the RSA cryptosystem. For many students, the material in the second half
of Chapter 7 is more suitable for a follow-up course. Chapter 8 describes, codes, and
analyzes several basic sorting algorithms, including the insertion sort, Shellsort,
mergesort, and quicksort, as well as indirect sorting. It also proves the classic lower
bound for sorting and discusses the related problems of selection. Finally, Chapter 9 is
a short chapter that discusses random numbers, including their generation and use in
randomized algorithms.
Part Three provides several case studies, and each chapter is organized around a
general theme. Chapter 10 illustrates several important techniques by examining games.
Chapter 11 discusses the use of stacks in computer languages by examining an algorithm
to check for balanced symbols and the classic operator precedence parsing algorithm.
Complete implementations with code are provided for both algorithms. Chapter 12
discusses the basic utilities of file compression and cross-reference generation, and
provides a complete implementation of both. Chapter 13 broadly examines simulation
by looking at one problem that can be viewed as a simulation and then at the more
classic event-driven simulation. Finally, Chapter 14 illustrates how data structures are
used to implement several shortest path algorithms efficiently for graphs.
Part Four presents the data structure implementations. Chapter 15 discusses inner
classes as an implementation technique and illustrates their use in the ArrayList
implementation. In the remaining chapters of Part Four, implementations that use simple
protocols (insert, find, remove variations) are provided. In some cases, Collections
API implementations that tend to use more complicated Java syntax (in addition to
being complex because of their large set of required operations) are presented. Some
mathematics is used in this part, especially in Chapters 19–21, and can be skipped at
the discretion of the instructor. Chapter 16 provides implementations for both stacks
and queues. First these data structures are implemented using an expanding array, then
they are implemented using linked lists. The Collections API versions are discussed at
the end of the chapter. General linked lists are described in Chapter 17. Singly linked
lists are illustrated with a simple protocol, and the more complex Collections API
version that uses doubly linked lists is provided at the end of the chapter. Chapter 18
describes trees and illustrates the basic traversal schemes. Chapter 19 is a detailed
chapter that provides several implementations of binary search trees. Initially, the basic
binary search tree is shown, and then a binary search tree that supports order statistics
is derived. AVL trees are discussed but not implemented, but the more practical red–
black trees and AA-trees are implemented. Then the Collections API TreeSet and
TreeMap are implemented. Finally, the B-tree is examined. Chapter 20 discusses hash
tables and implements the quadratic probing scheme as part of HashSet and HashMap,
after examination of a simpler alternative. Chapter 21 describes the binary heap and
examines heapsort and external sorting.
Part Five contains material suitable for use in a more advanced course or for general
reference. The algorithms are accessible even at the first-year level. However, for
completeness, sophisticated mathematical analyses that are almost certainly beyond the
reach of a first-year student were included. Chapter 22 describes the splay tree, which
is a binary search tree that seems to perform extremely well in practice and is
competitive with the binary heap in some applications that require priority queues.
Chapter 23 describes priority queues that support merging operations and provides an
implementation of the pairing heap. Finally, Chapter 24 examines the classic disjoint
set data structure.
The appendices contain additional Java reference material. Appendix A lists the
operators and their precedence. Appendix B has material on Swing, and Appendix C
describes the bitwise operators used in Chapter 12.
chapter dependencies
Generally speaking, most chapters are independent of each other. However, the
following are some of the notable dependencies.
Part One (Tour of Java): The first four chapters should be covered in their
entirety in sequence first, prior to continuing on to the rest of the text.
Chapter 5 (Algorithm Analysis): This chapter should be covered prior to
Chapters 6 and 8. Recursion (Chapter 7) can be covered prior to this chapter,
but the instructor will have to gloss over some details about avoiding inefficient
recursion.
Chapter 6 (The Collections API): This chapter can be covered prior to or in
conjunction with material in Part Three or Four.
Chapter 7 (Recursion): The material in Sections 7.1–7.3 should be covered
prior to discussing recursive sorting algorithms, trees, the Tic-Tac-Toe case
study, and shortest-path algorithms. Material such as the RSA cryptosystem,
dynamic programming, and backtracking (unless Tic-Tac-Toe is discussed) is
otherwise optional.
Chapter 8 (Sorting Algorithms): This chapter should follow Chapters 5 and 7.
However, it is possible to cover Shellsort without Chapters 5 and 7. Shellsort
is not recursive (hence there is no need for Chapter 7), and a rigorous analysis
of its running time is too complex and is not covered in the book (hence there is
little need for Chapter 5).
Chapter 15 (Inner Classes and Implementations of ArrayLists): This material
should precede the discussion of the Collections API implementations.
Chapters 16 and 17 (Stacks and Queues/Linked Lists): These chapters may be
covered in either order. However, I prefer to cover Chapter 16 first because I
believe that it presents a simpler example of linked lists.
Chapters 18 and 19 (Trees/Binary Search Trees): These chapters can be
covered in either order or simultaneously.
separate entities
mathematics
I have attempted to provide mathematical rigor for use in Data Structures courses that
emphasize theory and for follow-up courses that require more analysis. However, this
material stands out from the main text in the form of separate theorems and, in some
cases, separate sections or subsections. Thus it can be skipped by instructors in courses
that deemphasize theory.
In all cases, the proof of a theorem is not necessary to the understanding of the
theorem’s meaning. This is another illustration of the separation of an interface (the
theorem statement) from its implementation (the proof). Some inherently mathematical
material, such as Sections 7.4 (Numerical Applications of Recursion), can be skipped
without affecting comprehension of the rest of the chapter.
course organization
A crucial issue in teaching the course is deciding how the materials in Parts Two–Four
are to be used. The material in Part One should be covered in depth, and the student
should write one or two programs that illustrate the design, implementation, testing of
classes and generic classes, and perhaps object-oriented design, using inheritance.
Chapter 5 discusses Big-Oh notation. An exercise in which the student writes a short
program and compares the running time with an analysis can be given to test
comprehension.
In the separation approach, the key concept of Chapter 6 is that different data
structures support different access schemes with different efficiency. Any case study
(except the Tic-Tac-Toe example that uses recursion) can be used to illustrate the
applications of the data structures. In this way, the student can see the data structure and
how it is used but not how it is efficiently implemented. This is truly a separation.
Viewing things this way will greatly enhance the ability of students to think abstractly.
Students can also provide simple implementations of some of the Collections API
components (some suggestions are given in the exercises in Chapter 6) and see the
difference between efficient data structure implementations in the existing Collections
API and inefficient data structure implementations that they will write. Students can
also be asked to extend the case study, but again, they are not required to know any of
the details of the data structures.
Efficient implementation of the data structures can be discussed afterward, and
recursion can be introduced whenever the instructor feels it is appropriate, provided it
is prior to binary search trees. The details of sorting can be discussed at any time after
recursion. At this point, the course can continue by using the same case studies and
experimenting with modifications to the implementations of the data structures. For
instance, the student can experiment with various forms of balanced binary search trees.
Instructors who opt for a more traditional approach can simply discuss a case study
in Part Three after discussing a data structure implementation in Part Four. Again, the
book’s chapters are designed to be as independent of each other as possible.
exercises
Exercises come in various flavors; I have provided four varieties. The basic In Short
exercise asks a simple question or requires hand-drawn simulations of an algorithm
described in the text. The In Theory section asks questions that either require
mathematical analysis or asks for theoretically interesting solutions to problems. The In
Practice section contains simple programming questions, including questions about
syntax or particularly tricky lines of code. Finally, the Programming Projects section
contains ideas for extended assignments.
pedagogical features
The Key Concepts section lists important terms along with definitions and page
references.
The Common Errors section at the end of each chapter provides a list of
commonly made errors.
References for further reading are provided at the end of most chapters.
supplements
A variety of supplemental materials are available for this text. The following resources
are available at http://www.aw.com/cssupport for all readers of this textbook:
Source code files from the book. (The On the Internet section at the end of each
chapter lists the filenames for the chapter’s code.)
In addition, the following supplements are available to qualified instructors. To access
them, visit http://www.pearsonhighered.com/cs and search our catalog by title for Data
Structures and Problem Solving Using Java. Once on the catalog page for this book,
select the link to Instructor Resources.
PowerPoint slides of all figures in the book.
Instructor’s Guide that illustrates several approaches to the material. It includes
samples of test questions, assignments, and syllabi. Answers to select exercises
are also provided.
acknowledgments
Many, many people have helped me in the preparation of this book. Many have already
been acknowledged in the prior edition and the related C++ version. Others, too
numerous to list, have sent e-mail messages and pointed out errors or inconsistencies in
explanations that I have tried to fix in this edition.
For this edition I would like to thank my editor Michael Hirsch, editorial assistant
Stephanie Sellinger, senior production supervisor Marilyn Lloyd, and project manager
Rebecca Lazure and her team at Laserwords. Thanks also go to Allison Michael and
Erin Davis in marketing and Elena Sidorova and Suzanne Heiser of Night & Day
Design for a terrific cover.
Some of the material in this text is adapted from my textbook Efficient C
Visit https://testbankfan.com
now to explore a rich
collection of testbank or
solution manual and enjoy
exciting offers!
Programming: A Practical Approach (Prentice Hall, 1995) and is used with
permission of the publisher. I have included end-of-chapter references where
appropriate.
My World Wide Web page, , will contain
updated source code, an errata list, and a link for receiving bug reports.
M. A. W.
Miami, Florida
contents
1.2.2
1.3.2 constants
1.5.7 and
1.6 methods
1.6.1 overloading of method names
summary
key concepts
common errors
on the internet
exercises
references
2.3 strings
2.3.1 basics of string manipulation
2.4 arrays
2.4.1 declaration, assignment, and methods
2.4.3
summary
key concepts
common errors
on the internet
exercises
references
3.3 javadoc
(A Dutch Receipt.)
Prepare some finely flavoured carrots as above, and dry them
over a gentle fire like mashed turnips; then for a dish of moderate
size mix well with them from two to three ounces of good butter, cut
into small bits, keeping them well stirred. Add a seasoning of salt
and cayenne, and serve them very hot, garnished or not at pleasure
with small sippets (croutons) of fried bread.
CARROTS AU BEURRE, OR BUTTERED CARROTS.
(French.)
Either boil sufficient carrots for a dish quite tender, and then cut
them into slices a quarter of an inch thick, or first slice, and then boil
them: the latter method is the most expeditious, but the other best
preserves the flavour of the vegetable. Drain them well, and while
this is being done just dissolve from two to three ounces of butter in
a saucepan, and strew in some minced parsley, some salt, and white
pepper or cayenne; then add the carrots, and toss them very gently
until they are equally covered with the sauce, which should not be
allowed to boil: the parsley may be omitted at pleasure. Cold carrots
may be re-warmed in this way.
CARROTS IN THEIR OWN JUICE.
Boil them until they are about half done, lift them out, and let them
cool; slice them rather thickly, sprinkle them with fine salt and white
pepper, and fry them a pale brown in good butter. Serve them with
roast meat, or dish them under it.
JERUSALEM ARTICHOKES.
Wash the artichokes, pare them quickly, and throw them as they
are done into a saucepan of cold water, or of equal parts of milk and
water; and when they are about half boiled add a little salt to them.
Take them up the instant they are perfectly tender: this will be in from
fifteen to twenty-five minutes, so much do they vary in size and as to
the time necessary to dress them. If allowed to remain in the water
after they are done, they become black and flavourless. Melted
butter should always be sent to table with them.
15 to 25 minutes.
TO FRY JERUSALEM ARTICHOKES. (ENTREMETS.)
Boil them from eight to twelve minutes; lift them out, drain them on
a sieve, and let them cool; dip them into beaten eggs, and cover
them with fine bread-crumbs. Fry them a light brown, drain, pile them
in a hot dish, and serve them quickly.
JERUSALEM ARTICHOKES, À LA REINE.
Boil them tender, press the water well from them, and then
proceed exactly as for mashed turnips, taking care to dry the
artichokes well, both before and after the milk or cream is added to
them; they will be excellent if good white sauce be substituted for
either of these.
HARICOTS BLANCS.
Wash the roots delicately clean, but neither scrape nor cut them,
for should even the small fibres be taken off before they are cooked,
their beautiful colour would be much injured. Throw them into boiling
water, and, according to their size, which varies greatly, as they are
sometimes of enormous growth, boil them from one hour and a half
to two and a half, or longer if requisite. Pare and serve them whole,
or cut into thick slices and neatly dished in a close circle: send
melted butter to table with them. Cold red beet root is often
intermingled with other vegetables for winter salads; and it makes a
pickle of remarkably brilliant hue. A common mode of serving it at
the present day is in the last course of a dinner with the cheese: it is
merely pared and sliced after having been baked or boiled tender.
1-1/2 to 2-1/2 hours, or longer.
TO BAKE BEET ROOT.
Bake or boil it tolerably tender, and let it remain until it is cold, then
pare and cut it into slices; heat and stew it for a short time in some
good pale veal gravy (or in strong veal broth for ordinary occasions),
thicken this with a teaspoonful of arrow-root, and half a cupful or
more of good cream, and stir in, as it is taken from the fire, from a
tea to a tablespoonful of chili vinegar. The beet root may be served
likewise in thick white sauce, to which, just before it is dished, the
mild eschalots of page 128 may be added.
TO STEW RED CABBAGE.
(Flemish Receipt.)
Strip the outer leaves from a fine and fresh red cabbage; wash it
well, and cut it into the thinnest possible slices, beginning at the top;
put it into a thick saucepan in which two or three ounces of good
butter have been just dissolved; add some pepper and salt, and stew
it very slowly indeed for three or four hours in its own juice, keeping it
often stirred, and well pressed down. When it is perfectly tender add
a tablespoonful of vinegar; mix the whole up thoroughly, heap the
cabbage in a hot dish, and serve broiled sausages round it; or omit
these last, and substitute lemon-juice, cayenne pepper, and a half-
cupful of good gravy.
The stalk of the cabbage should be split in quarters and taken
entirely out in the first instance.
3 to 4 hours.
BRUSSELS SPROUTS.
Boil the salsify tender, as directed above, drain, and then press it
lightly in a soft cloth. Make some French batter (see Chapter V.),
throw the bits of salsify into it, take them out separately, and fry them
a light brown, drain them well from the fat, sprinkle a little fine salt
over them after they are dished, and serve them quickly. At English
tables, salsify occasionally makes its appearance fried with egg and
bread-crumbs instead of batter. Scorgonera is dressed in precisely
the same manner as the salsify.
BOILED CELERY.
Cut five or six fine roots of celery to the length of the inside of the
dish in which they are to be served; free them from all the coarser
leaves, and from the green tops, trim the root ends neatly, and wash
the vegetable in several waters until it is as clean as possible; then,
either boil it tender with a little salt, and a bit of fresh butter the size
of a walnut, in just sufficient water to cover it quite, drain it well,
arrange it on a very hot dish, and pour a thick béchamel, or white
sauce over it; or stew it in broth or common stock, and serve it with
very rich, thickened, Espagnole or brown gravy. It has a higher
flavour when partially stewed in the sauce, after being drained
thoroughly from the broth. Unless very large and old, it will be done
in from twenty-five to thirty minutes, but if not quite tender, longer
time must be allowed for it. A cheap and expeditious method of
preparing this dish is to slice the celery, to simmer it until soft in as
much good broth as will only just cover it, and to add a thickening of
flour and butter, or arrow-root, with some salt, pepper, and a small
cupful of cream.
25 to 30 minutes, or more.