insert
, contains
, and remove
.Hash tables can be used to implement the Set ADT. Write pseudocode for the three main Set operations, insert
, contains
, remove
for the HashSet below, which is specific to integers.
public class IntHashSet {
LinkedList<Integer>[] A; // an array of LinkedList<Integer>s
// assume a constructor is implemented that instantiates A
/** insert value into the set. return false if the value
* was already in the set, true otherwise */
boolean insert(int value);
/** return true if value is in the set,
* false otherwise */
boolean contains(int value);
/** remove value from the set. return true if the
* value was in the set, false otherwise */
boolean remove(int value);
}
What’s the minimum and maximum load factor of a hash table that uses chaining for collision resolution?
In the following problems, assume that the hash function can be computed in constant time.
contains
, remove
, and insert
in a HashSet that has \(N\) entries and capacity \(C\)?contains
, remove
, and insert
?IntHashSet
from above, but generic). Describe how you could go about using the Set to implement a Map. Describe any initial setup needed, then for each Map method (get
, put
, remove
) describe how you would implement it using the Set’s methods (insert
, contains
, remove
). Hint: Consider this perspective: a Map is very much like a Set of key-value pairs in which the keys are unique.