Ch23 - Hashing As A Dictionary Implementation Full Test Bank - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 23 - Hashing as a Dictionary Implementation
True/False (15)
- The successful addition of a new entry in a dictionary occurs after a search for a given key fails.
- An unsuccessful addition is the result of an unsuccessful search for a given key.
- The cost of a successful search for an entry is less than the cost of inserting that entry.
- An unsuccessful removal of an entry has the same efficiency as an unsuccessful search.
- Collision resolution takes less time than evaluating the hash function.
- Collision resolution is the main contributor to the cost of hashing.
- In separate chaining, λ has no maximum value.
- In separate chaining, the number of entries cannot exceed the size of the hash table.
- λ is the cost of collision resolution.
- All open addressing schemes use more than one location in the hash table per entry.
- If you use double hashing for collision resolution, it is recommended that the hash table be less than half full.
- The degradation in performance as λ increases is more severe than linear probing.
- A location in the hash table that is in the available state contains an entry in the removed state.
- An odd integer 5 or greater is prime if it is not divisible by every odd integer up to its square root.
- Hashing as a dictionary implementation does not support operations that involve sorted search keys.
Short Answer (7)
- What is λ for a hash table with 500 locations and 200 entries that uses open addressing?
- What is λ for a hash table with 200 locations and 50 entries that uses open addressing?
- Explain why resizing a hash table that has 751 entries to double the size, or 1502, is a bad idea.
- Given a table size of 13, the hash function h(k) = k % table size, and the entries 14, 2, 15, 26 and 29, show the hash table after the five entries are inserted into the table using open addressing with linear probing.
2 % 13 = 2
15 % 13 = 2 << collision
26 % 13 = 0
29 % 13 = 3 << collision
index 0 1 2 3 4 5 6 7 8 9 10 11 12
entry 26 14 2 15 29
- Given the following hash table whose size is 13 and the hash function h(k) = k % table size, show the hash table after rehashing to a table size of 17, using open addressing with linear probing.
index 0 1 2 3 4 5 6 7 8 9 10 11 12
entry 12 7 14 23 37 28
7 % 17 = 7
14 % 17 = 14
23 % 17 = 6
37 % 17 = 3
28 % 17 = 11
index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
entry 37 23 7 28 12 14
- Given a table size of 19, the hash function h(k) = k % table size, and the entries 19, 38, 20, 39 and 21, show the hash table after the five entries are inserted into the table using open addressing with linear probing.
38 % 19 = 0 << collision
20 % 19 = 1 << collision
39 % 19 = 1 << collision
21 % 19 = 2 << collision
index 0 1 2 3 4 5 6 7 8 9 10 11 12
entry 19 38 20 39 21
- Given a table size of 19, the hash function h(k) = k % table size, and the entries 19, 38, 20, 39 and 21, show the hash table after the five entries are inserted into the table using buckets.
38 % 19 = 0 << collision
20 % 19 = 1 << collision
39 % 19 = 1 << collision
21 % 19 = 2 << collision
index 0 1 2 3 4 5 6 7 8 9 10 11 12
entry 19 20 21
38 39
Multiple Choice (22) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- Hashing is a good technique for implementing a dictionary when _____ is the primary task.
- searching
- sorting
- adding entries
- removing entries
- Which dictionary operation searches the hash table for a given search key?
- getValue
- remove
- add
- all of the above
- The successful addition of a new entry in a dictionary occurs
- after a search for a given key fails
- after a search for a given key succeeds
- after linear probing
- after quadratic probing
- The cost of a successful search for an entry is _____ the cost of inserting that entry.
- The same as
- more than
- less than
- unrelated to
- What is the ratio of the size of the dictionary to the size of the hash table called?
- load factor
- hash factor
- fullness quotient
- hash ratio
- When a hash table is empty, λ is
- 0
- 0.1
- 1
- undefined
- When λ = 0 the hash table
- is empty
- is full
- is ready to resized
- needs to be created
- When a hash table is full, λ is
- 1
- 0.1
- 0
- undefined
- λ is a measure of
- the cost of collision resolution
- hashing
- linear probing
- increasing the table size
- What is λ in a hash table whose size is 150 that has 45 entries?
- 0.3
- 0.45
- 3.33
- 0.25
- If you use quadratic probing for collision resolution, it is recommended that the hash table be
- less than half full
- more than half full
- almost empty
- extended to use buckets
- In separate chaining, λ is
- the average number of dictionary entries per chain
- the maximum number of dictionary entries per chain
- the number of indexes without a chain
- the number of indexes with a chain
- If you can find a perfect hash function for you particular set of keys, the ADT dictionary will provide operations with efficiency of
- O(1)
- O(log n)
- O(n)
- O(n2)
- To maintain reasonable efficiency in hashing with separate chaining, you should keep
- λ < 1
- λ = 1
- λ > 1
- λ < 100
- The average number of comparisons for an unsuccessful search when hashing with separate chaining is
- λ
- 1 + λ / 2
- n / λ
- n
- The average number of comparisons for a successful search when hashing with separate chaining is
- 1 + λ / 2
- λ
- n / λ
- n
- Enlarging a hash table and computing new hash indices for its contents is called
- rehashing
- resizing
- linear expansion
- quadratic expansion
- In hashing with open addressing, an empty location is represented by
- null
- 0
- an empty flag
- none of the above
- In the class HashDictionary, the method remove returns _____ if the key is not found.
- null
- -1
- 0
- throws a KeyNotHashedException
- In the class HashDictionary, the method getValue returns _____ if the key is not found.
- null
- -1
- 0
- throws a KeyNotHashedException
- Given a table size of 19 the hash function h(k) = k % table size, what index does the entry 24 map to?
- 5
- 4
- 19
- 24
- Given a table size of 13 the hash function h(k) = k % table size, what index does the entry 26 map to?
- 0
- 13
- 26
- 12
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano