Chapter 14 APCSA
Chapter 14 APCSA
TRUE/FALSE
3. Collections must be homogeneous, meaning the items are all of the same type.
4. The contents and size of a collection typically do not change during the course of a program.
5. In modern languages like Java, arrays are considered a lower-level data structure and are often used to
implement other collections.
7. A list tracks its own logical size and grows or shrinks automatically as needed.
8. A map is a collection of unique items called entries. Each entry contains a key and a value.
MODIFIED TRUE/FALSE
ANS: F, dynamic
3. The replacement operation combines removal and insertion into a single operation.
____________________
4. The index positions available for access in a list range from 0 to its physical size minus 1.
____________________
ANS: F, logical
5. Infix evaluation applies operators as soon as they are encountered and never requires parentheses.
____________________
ANS: F, postfix
MULTIPLE CHOICE
2. A(n) ____ is a linear sequence of elements of any type by numeric index position.
a. string c. stack
b. list d. queue
ANS: B PTS: 1 REF: 536
3. A(n) ____ is a linear sequence of characters with access to the end, called the top.
a. string c. stack
b. list d. queue
ANS: C PTS: 1 REF: 536
6. Like an array, a(n) ____ is a sequence of elements that are ordered by an integer index position.
a. queue c. stack
b. list d. all of the above
ANS: B PTS: 1 REF: 540
8. When a name such as E is used to specify a type in an interface, it is called a type ____.
a. parameter c. character
b. variable d. element
ANS: B PTS: 1 REF: 541
9. When a name such as String takes the place of the type variable during instantiation, it is called a type
____.
a. parameter c. character
b. array d. element
ANS: A PTS: 1 REF: 541
14. The ____ of two sets (A and B) is a set that contains all of the items in A and all of the items in B.
a. union c. subset
b. intersection d. collection
ANS: A PTS: 1 REF: 563
15. The ____ of two sets (A and B) is the set of items in A that are also items in B.
a. union c. subset
b. intersection d. collection
ANS: B PTS: 1 REF: 563
16. Each type of collection supports some form of all of the following EXCEPT ____.
a. addition c. membership
b. removal d. hierarchy
ANS: D PTS: 1 REF: 574
17. When a method signature starts with the modifier ____, it means that the user of the method sends a
message to the main class, not to an instance of any class.
a. static c. private
b. public d. superclass
ANS: A PTS: 1 REF: 577
FIGURE 14-1
19. Java’s built-in collections are defined in the package ____, as shown in Figure 14-1 above.
a. java.groups c. java.collections
b. java.sets d. java.util
ANS: D PTS: 1 REF: 537 | 538
20. In Figure 14-1 above, the Collection interface extends the ____ interface.
a. list c. Iterable
b. set d. both a. and b.
ANS: C PTS: 1 REF: 538
Case 14-1
Natasha is using collections to organize data in a program that organizes processes such as CPU and
printer access.
Case 14-2
Chase needs to organize data for his dictionary program.
24. Which of the following is NOT true about how Chase will organize his data?
a. The values are unique.
b. The keys are unique.
c. The keys are in no particular order.
d. The value associated with a key contains the attributes of the identifier.
ANS: A PTS: 1 REF: 566 TOP: Critical Thinking
COMPLETION
1. A(n) ____________________ contains a group of items that are treated as a conceptual unit.
ANS: collection
2. A feature called ____________________ classes allows storage of primitive data types in lists.
ANS: wrapper
3. A(n) ____________________ is an object that allows the programmer to visit all of the elements in a
collection.
ANS: iterator
ANS:
hash
hashing
ANS:
map
table
map or table
table or map
MATCHING
Identify the letter of the choice that best matches the phrase or definition.
a. Queue
b. Set
c. Map
d. Tree
e. Graph
1. An unordered collection of elements accessed by unique keys.
2. A network of elements.
3. An unordered collection of unique elements
4. A linear sequence of elements with insertions at the rear and removals at the front.
5. A hierarchical collection of elements.
ESSAY
1. List three operations common to all collections. What does it mean if an operation is optional? What is
the difference between Collections (plural) and Collection (singular)?
ANS:
All collections support some form of addition and removal of elements, as well as a way to test for
membership. Other common operations:
1. Add the elements of one collection to another collection.
2. Remove all the elements of one collection from another collection.
3. Retain only the elements of one collection that are present in another collection.
4. Determine if one collection contains all the elements in another collection.
An optional operation means that the implementing class must include these methods, but need not
support them.
Collections (plural) is the name of a class (like the Math class), whereas Collection (singular) is the
name of the interface implemented by a set of collection classes.