Deck 7: Sets and Maps
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/27
Play
Full screen (f)
Deck 7: Sets and Maps
1
Using a hash table enables us to retrieve an item in O(n2) time.
False
2
Collections implementing the Set interface must contain unique elements.
True
3
Sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element.
True
4
With respect to hash tables, if there are no collisions, the performance for search and retrieval is O(n), regardless of table size.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
5
Although you cannot reference a specific element of a Set, you can iterate through all its elements using an Iterator object.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
6
The basis of ____________________ is to transform the item's key value to an integer value which will then be transformed into a table index.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
7
In ____________________ addressing, each hash table element (type Object) references a single key-value pair.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
8
The Java API implements the Set using a(n) ____________________.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
9
The problem with ____________________ probing is that it tends to form clusters of keys in the table, causing longer search chains.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
10
Mathematically, a(n) ___________________ is a set of ordered pairs whose elements are known as the key and the value.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
11
An alternative to open addressing is a technique called _____________________.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
12
An addressing technique in which each table element references a linked list that contains all the items that hash to the the same table index is referred to as _________________________.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
13
In ____________________ addressing, search chains can overlap, so a search chain may include items in the table that have different starting values.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
14
An advantage of ____________________ is that you can store more elements in the table than the number of table slots (indexes).
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
15
One requirement on the key-value pair for a Map object is to implement the interface ____________________, which is an inner interface of interface Map.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
16
Method ____ creates a set view of the entries in a Map.
A) setIterator
B) getValue
C) getKey
D) entrySet
A) setIterator
B) getValue
C) getKey
D) entrySet
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
17
____ occur(s) because you can only store one key-value pair in a given array element.
A) Quadratic probing
B) Hashing
C) Collisions
D) Backtracking
A) Quadratic probing
B) Hashing
C) Collisions
D) Backtracking
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
18
If we compare hash table performance with binary search of a sorted array, the number of comparisons required by binary search is ____.
A) O(1)
B) O(n)
C) O(log2n)
D) O(log n)
A) O(1)
B) O(n)
C) O(log2n)
D) O(log n)
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
19
The intersection of sets A, B is a set ____.
A) whose elements belong to A but not to B
B) whose elements belong to both A and B
C) whose elements belong either to A or B or to both A and B
D) set where every element of A is also an element of B
A) whose elements belong to A but not to B
B) whose elements belong to both A and B
C) whose elements belong either to A or B or to both A and B
D) set where every element of A is also an element of B
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following is a commonly used method of the Set interface?
A) boolean ContainsAll(Collection<E> coll)
B) boolean retain<E>(E obj)
C) boolean remove(Collection coll)
D) boolean Empty()
A) boolean ContainsAll(Collection<E> coll)
B) boolean retain<E>(E obj)
C) boolean remove(Collection coll)
D) boolean Empty()
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
21
With respect to the Map interface, the ____ method returns the current value associated with a given key.
A) isEmpty
B) insert
C) put
D) get
A) isEmpty
B) insert
C) put
D) get
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
22
With respect to the Map interface, the ____ method either inserts a new mapping or changes the value associated with an existing mapping.
A) get
B) isEmpty
C) put
D) insert
A) get
B) isEmpty
C) put
D) insert
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is an example of a map?
A) { (J, Jane), (B, Bill), (S, Sam), (B1, Bob), (B, Bill) }
B) { (J, Jane), (B, Bill), (S, Sam), (B1, Bob), (B2, Bill) }
C) { (J, Jane), (B, Bill), (S, Sam), (B1, Bob), (J, Jane) }
D) { (S, Sam), (B, Bill), (S, Sam), (B1, Bob), (B2, Bill) }
A) { (J, Jane), (B, Bill), (S, Sam), (B1, Bob), (B, Bill) }
B) { (J, Jane), (B, Bill), (S, Sam), (B1, Bob), (B2, Bill) }
C) { (J, Jane), (B, Bill), (S, Sam), (B1, Bob), (J, Jane) }
D) { (S, Sam), (B, Bill), (S, Sam), (B1, Bob), (B2, Bill) }
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
24
The union of two sets A, B is a(n) ____.
A) set whose elements belong to both A and B
B) set whose elements belong to A but not to B
C) set where every element of A is also an element of B
D) set whose elements belong either to A or B or to both A and B
A) set whose elements belong to both A and B
B) set whose elements belong to A but not to B
C) set where every element of A is also an element of B
D) set whose elements belong either to A or B or to both A and B
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
25
The following is an algorithm for ____.
Compute the index by taking the item's hashCode() % table.length.
If table[index] is null
The item is not in the table.
Else if table[index] is equal to the item
The item is in the table.
Else
Continue to search the table by incrementing the index until either the item is found or a null entry is found.
A) rehashing
B) accessing an item in a hash table
C) deleting an item in a hash table
D) inserting an item in a hash table
Compute the index by taking the item's hashCode() % table.length.
If table[index] is null
The item is not in the table.
Else if table[index] is equal to the item
The item is in the table.
Else
Continue to search the table by incrementing the index until either the item is found or a null entry is found.
A) rehashing
B) accessing an item in a hash table
C) deleting an item in a hash table
D) inserting an item in a hash table
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
26
A NavigableSet (NavigableMap) allows the programmer to create _____________ of a Set (Map).
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
27
A NavigableSet (NavigableMap) can be traversed in reverse order.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck