Chapter 27 Hashing
Section 27.2 What Is Hashing?
1. A hashing function .
a. stores an element in the hash table
b. maps a key to an index in the hash table
#
2. If each key is mapped to a different index in the hash table, it is called .
a. normal hashing
b. perfect hashing
#
3. A collision occurs .
a. when two or more keys are mapped to the same hash value.
b. when two elements have the same key value.
c. when two elements are mapped to the same key.
#
Section 27.3 Hash Functions and Hash Codes
5. What is the return type value for the hashCode() method?
a. byte
b. short
c. int
d. long
#
6. True or False? Two objects have the same hash codes if they are equal.
a. True
b. False
#
7. True or False? Two objects are equal if their hash codes are equal.
a. True
b. False
#
4. Every object has the hashCode() method.
a. True
b. False
#
Section 27.3.1 Hash Codes for Primitive Types
9. For an Integer object with value 20, what is its hashCode?
a. 10
b. 20
c. 30
#
Section 27.3.2 Hash Codes for Strings
8. If two strings are equal, the two strings have the same hashCodes.
a. True
b. False
#
Section 27.3.3 Compressing Hash Codes
4. True or False? Assume N and hashCode are positive and N is an integer of power of 2, hashCode % N is the same
as hashCode & (N1).
a. True
#
10. 1 & 3 is .
a. 0
b. 1
c. 2
d. 3
#
10. 1 << 2 is .
a. 2
b. 3
c. 4
d. 5
#
Section 27.4 Handling Collision Using Open Addressing
12. When a collision occurs during the insertion of an entry to a hash table, finds the next available location
sequentially.
a. linear probing
b. quadratic probing
c. double hashing.
#
Section 27.5 Handling Collision Using Separate Chaining
11. is to find an open location in the hash table in the event of collision.
a. Open addressing
b. Separate chaining
#
13. The places all entries with the same hash index into the same location, rather than finding new
locations.
a. open addressing scheme
b. separate chaining scheme
#
Section 27.6 Load Factor and Rehashing
14. measures how full the hash table is.
a. Load factor
b. Threshold