5th Edition Full Test Bank Ch.22 Sets And Maps - Instructor Test Bank | Java Foundations 5e Lewis by John Lewis. DOCX document preview.
Chapter 22: Sets and Maps
Multiple Choice Questions:
1) A set is
a) an ordered list of elements
b) a collection of elements with no duplicate elements
c) a collection whose elements have two important attributes, keys and values
d) a collection of elements, each of which reference 0, 1, or 2 other elements in the collection
e) a collection of elements all of which are the same
2) A map is
a) an ordered list of elements
b) a collection of elements with no duplicate elements
c) a collection whose elements have two important attributes, keys and values
d) a collection of elements, each of which reference 0, 1, or 2 other elements in the collection
e) a collection of elements all of which are the same
3) In a map,
a) the values are unique
b) the keys are unique
c) the size of each element is unique
d) the references are unique
e) the exceptions are unique
4) Which operation below is not part of the Map interface?
a) Given a key, determine the value associated with the key in a map.
b) Determine if a key is in an element in a map.
c) Determine if a value is in in an element in a map.
d) Given a value, determine the key that is associated with the value in a map.
e) All of these operations are part of the Map interface
5) When implementing a set or a map using hashing, the two parameters for the constructor of the collection are the ___ and the ___ of the hash table
a) minimum size, maximum size
b) starting subscript, ending subscript
c) initial capacity, load factor
d) number of rows, number of columns
e) none of the above
6) A perfect hashing function
a) maps elements of the same size to the same position in the hash table
b) maps elements to the next sequentially available space in the hash table
c) maps elements of the same class to the same position in the hash table
d) maps each element to a unique position in the hash table
e) is not possible
7) The load factor of a hashing function determines
a) the limit on the size of the elements that are added to the hash table
b) how full a hash table must be before it is resized
c) the size of the argument to the hashing function
d) how quickly an element can be located in the hash table
e) none of these is correct
8) A hashCode method returns a(n)
a) int
b) double
c) key
d) value
e) String
9) The TreeMap and TreeSet classes use a ________ for the underlying data structure.
a) heap
b) double-ended queue
c) red/black tree
d) circular queue
e) full tree
10) In a set, the ______ must be unique.
a) data types
b) keys
c) values
d) elements
e) none of the above
11) A(n) ______ occurs when two elements have the same resulting value from the hashing function.
a) collision
b) collusion
c) coercion
d) capacity
e) instantiation
12) Which of the following pairs of data items could be stored in a map?
a) a student’s name and the student’s student ID number
b) a student’s name and the student’s grade point average (GPA)
c) a student’s name and the student’s year in school
d) a student’s name and the name of the dormitory in which the student lives
e) None of these pairs are appropriate for storage in a map.
True/False Questions:
1) A set is an ordered collection of elements.
2) In a map, each value has a unique key.
3) The elements in a map are unique.
4) The contains operation of the Set interface returns a count of the number of occurrences of an element in the set
5) When instantiating an implementation of a Map interface, a type must be supplied for both the key and for the value.
6) The primary purpose of a set is to determine if a particular element is a member of the set.
7) Set is not the only collection type that supports testing for membership.
8) Sets and maps can be implemented using either binary trees or by using a hashing function.
9) A hashing function is a function that maps elements of a set or a map to other elements that are in the set or the map.
10) When implementing a map class or a set class using a tree data structure, a heap is used for the tree.
Short Answer Questions:
1) What should the hashCode function return if it is passed the same object more than once?
2) If the equals method indicates that two objects are not equal, then what should the hashCode function return for these objects?
3) Maps and sets are both collections of objects. In what ways are they different?
4) The map collection has a ‘get’ operation. Why doesn’t the set collection have a ‘get’ operation?
5) When implementing and instantiating a map, how many types must be supplied?
6) A fastener company has products that are referenced by their names and by their part numbers. Here is a small sample list:
name | part number |
bolt | a11b12 |
nut | a11c12 |
washer | a11d12 |
screw | a12d12 |
bolt | b12b12 |
nut | b12c12 |
washer | b12d12 |
Based on this small sample list, explain how you would implement this information in a map.
7) When implementing a hashCode function, must the function make use of the entire object that it receives as an argument?
8) What are the parameters that are passed to the constructor of the HashMap or the HashSet class?
9) What does it mean for a hashing function to be “perfect”? Is this a desirable property, or should it be avoided?
10) A HashMap object is created with an initial capacity of 500 and a load factor of 0.8. How many elements are in the map when the hash table is resized?