Data Structures and Abstractions with Java, 5th edition
by Frank Carrano, Timothy Henry
LU
XE
LI
BR
AR
Y
, TABLE OF CONTENT
Bags
Java Interlude 1 Generics
Bag Implementations That Use Arrays
Java Interlude 2 Exceptions
A Bag Implementation That Links Data
The Efficiency of Algorithms
Stacks
Stack Implementations
Java Interlude 3 More About Exceptions
Queues, Deques, and Priority Queues
Queue, Deque, and Priority Queue Implementations
LU
Recursion
Lists
A List Implementation That Uses an Array
A List Implementation That Links Data
Java Interlude 4 Iterators
Iterators for the ADT List
XE
Problem Solving With Recursion
Java Interlude 5 More About Generics
An Introduction to Sorting
Faster Sorting Methods
Java Interlude 6 Mutable and Immutable Objects
LI
Sorted Lists
Java Interlude 7 Inheritance and Polymorphism
Inheritance and Lists
Searching
BR
Java Interlude 8 Generics Once Again
Dictionaries
Dictionary Implementations
Introducing Hashing
Hashing as a Dictionary Implementation
Trees
AR
Tree Implementations
Java Interlude 9 Cloning
A Binary Search Tree Implementation
A Heap Implementation
Balanced Search Trees
Graphs
Y
Graph Implementations
Appendices
A. Documentation and Programming Style
B. Java Classes
C. Creating Classes from Other Classes
, KJHGFDSA
Chapter 1 - Bags
True/False (10) All Chapters Included
1. An abstract data type is not necessarily a collection.
All Answers Included
Answer: true
2. A collection is not necessarily an abstract data type.
LU
Answer: false
3. Entries of a bag can belong to classes related by inheritance.
Answer: true
XE
4. Entries of a bag may belong to different classes because items are unordered.
Answer: false
5. All entries of a bag must have the same data type or a subtype of that data type.
LI
Answer: true
6. By declaring a data type to be a BagInterface, we can replace the bag class with another class
that implements the BagInterface.
BR
Answer: true
7. A method can change the state of an object passed to it as an argument.
Answer: true
AR
8. A set is a special kind of bag.
Answer: true
9. You cannot determine the exact number of times a particular item appears in a bag because it is
unordered.
Y
Answer: false
10. Code written with respect to an interface makes it difficult to replace one implementation of a
bag with another.
Answer: false
jkhgfdsa
, KJHGFDSA
Short Answer (5)
1. Explain the rationale for returning a Boolean value from the add bag operation.
Answer: A client should know what happened. A Boolean value indicates true for success or false
for a failed operation.
2. Explain why writing a test program before implementing a class is a good idea.
Answer: It helps you understand the specifications before committing to your design and
LU
implementation.
3. Explain why the set ADT does not need a getFrequencyOf operation.
Answer: Because sets do not contain duplicate items, only a 0 for absence or 1 for presence of an
item would be returned. Using a contains method is a better design.
XE
4. What is the design rationale for providing a toArray method instead of a displayBag method?
Answer: The user/client is free to display any or all of the items in any way desired.
5. Explain why null is a potential return value for the remove operation.
LI
Answer: It is a value that cannot be in the bag and therefore signals a problem if, for example, a
client tries to remove an entry from an empty bag.
BR
Multiple Choice (30) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED
WITH **. YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
1. A language-independent specification for a group of values and operations on those values is
called a/an:
AR
a. abstract data type **
b. data structure
c. collection
d. primitive
2. An implementation of an ADT with a programming language is called a/an:
Y
a. data structure **
b. abstract data type
c. collection
d. primitive
3. An object that groups other objects and provides services to its clients is called a/an:
a. collection **
jkhgfdsa