[go: up one dir, main page]

100% found this document useful (2 votes)
13 views7 pages

Chapter 14 APCSA

Chapter 14 introduces collections, which are essential for organizing data in programming. It covers various types of collections such as lists, maps, and queues, highlighting their properties and operations. The chapter also discusses the differences between collection classes and interfaces, as well as common operations applicable to all collections.

Uploaded by

ethanrhafer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
13 views7 pages

Chapter 14 APCSA

Chapter 14 introduces collections, which are essential for organizing data in programming. It covers various types of collections such as lists, maps, and queues, highlighting their properties and operations. The chapter also discusses the differences between collection classes and interfaces, as well as common operations applicable to all collections.

Uploaded by

ethanrhafer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 14: Introduction to Collections

TRUE/FALSE

1. Collections are used to help programmers effectively organize data in programs.

ANS: T PTS: 1 REF: 535

2. Strings and arrays are examples of collections.

ANS: T PTS: 1 REF: 535

3. Collections must be homogeneous, meaning the items are all of the same type.

ANS: F PTS: 1 REF: 536

4. The contents and size of a collection typically do not change during the course of a program.

ANS: F PTS: 1 REF: 536

5. In modern languages like Java, arrays are considered a lower-level data structure and are often used to
implement other collections.

ANS: T PTS: 1 REF: 537

6. A list can contain values such as int and double.

ANS: F PTS: 1 REF: 542

7. A list tracks its own logical size and grows or shrinks automatically as needed.

ANS: T PTS: 1 REF: 545

8. A map is a collection of unique items called entries. Each entry contains a key and a value.

ANS: T PTS: 1 REF: 566

9. The most prevalent application of queues is in database management.

ANS: F PTS: 1 REF: 567

10. In a map, an attribute can also be an object’s key.

ANS: T PTS: 1 REF: 567

MODIFIED TRUE/FALSE

1. Collections are typically static. ____________________

ANS: F, dynamic

PTS: 1 REF: 536


2. The traversal operation visits each item in a collection in order to access or modify it.
____________________

ANS: T PTS: 1 REF: 537

3. The replacement operation combines removal and insertion into a single operation.
____________________

ANS: T PTS: 1 REF: 537

4. The index positions available for access in a list range from 0 to its physical size minus 1.
____________________

ANS: F, logical

PTS: 1 REF: 540

5. Infix evaluation applies operators as soon as they are encountered and never requires parentheses.
____________________

ANS: F, postfix

PTS: 1 REF: 557

MULTIPLE CHOICE

1. A(n) ____ is a linear sequence of characters accessed by numeric index position.


a. string c. stack
b. list d. queue
ANS: A PTS: 1 REF: 536

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

4. A(n) ____ provides a logical view of the behavior of a class of objects.


a. interface c. method
b. collection d. package
ANS: A PTS: 1 REF: 538

5. A programmer chooses a collection class based on ____.


a. the logic of an application c. the number of classes it implements
b. the collection’s run-time performance d. both a and b.
ANS: D PTS: 1 REF: 539

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

7. A programmer must use ____ to manipulate elements in a list.


a. the subscript operator [ ] c. methods
b. casting d. variables
ANS: C 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

10. The index-based operations on linked lists run in ____ time.


a. constant c. linear
b. consecutive d. analog
ANS: C PTS: 1 REF: 546

11. A ____ adheres to a Last In First Out protocol.


a. list c. queue
b. tree d. stack
ANS: D PTS: 1 REF: 555

12. Translating infix expressions to postfix form is an example of an application of a ____.


a. list c. queue
b. tree d. stack
ANS: D PTS: 1 REF: 557

13. A ____ adheres to a First In First Out protocol.


a. list c. queue
b. tree d. stack
ANS: C PTS: 1 REF: 560

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

18. An association list is another word for a(n) ____.


a. stack c. queue
b. map d. set
ANS: B PTS: 1 REF: 566

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.

21. Natasha should use a(n) ____.


a. stack c. queue
b. list d. map
ANS: C PTS: 1 REF: 561 TOP: Critical Thinking

22. In Natasha’s program, items will be added to the ____.


a. front c. top
b. pivot d. rear
ANS: D PTS: 1 REF: 560 TOP: Critical Thinking

Case 14-2
Chase needs to organize data for his dictionary program.

23. Chase should use a ____.


a. stack c. queue
b. list d. map
ANS: D PTS: 1 REF: 566 TOP: Critical Thinking

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

PTS: 1 REF: 535

2. A feature called ____________________ classes allows storage of primitive data types in lists.

ANS: wrapper

PTS: 1 REF: 543

3. A(n) ____________________ is an object that allows the programmer to visit all of the elements in a
collection.

ANS: iterator

PTS: 1 REF: 544


4. The ____________________ implementation technique supports close to constant time accesses,
insertions, and removals of elements from a collection.

ANS:
hash
hashing

PTS: 1 REF: 564

5. A(n) ____________________ is also known as a keyed list or dictionary.

ANS:
map
table
map or table
table or map

PTS: 1 REF: 566

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.

1. ANS: C PTS: 1 REF: 536


2. ANS: E PTS: 1 REF: 536
3. ANS: B PTS: 1 REF: 536
4. ANS: A PTS: 1 REF: 536
5. ANS: D PTS: 1 REF: 536

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.

PTS: 1 REF: 574-576 TOP: Critical Thinking

You might also like