Ch.22 - Introducing Hashing Test Bank - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 22 - Introducing Hashing
True/False (22)
- Most hash tables are not full.
- Any function can be a hash function if it produces an integer that is suitable to be used as an array index.
- A search key cannot be a primitive data type.
- The default hash code returned by the method hashCode in Java’s base class Object is a good choice for hashing.
- All classes inherit the method hashCode.
- The Java Object method hashCode returns an integer.
- Real-world data is uniformly distributed.
- Duplicate hash codes create collisions.
- If a class overrides the method equals, it should not override the method hashCode.
- If the method equals considers two objects to be equal, then the method hashCode must return the same value for both objects.
- Calling the method hashCode more than once on an object that has not been altered should return the same value.
- Calling the method hashCode during different program executions will not affect the value returned.
- The size of a hash table should always be an odd number.
- Using a hash table size that is a prime number distributes values through the index range better than if the size is an even number.
- Linear probing can examine every location in a hash table.
- You will never encounter a full table when linear probing is used.
- In open addressing with linear probing, a successful search for an entry that corresponds to a given search key could potentially follow a different probe sequence used to add the entry to the hash table.
- Linear probing is apt to cause secondary clustering.
- Quadratic probing is apt to cause secondary clustering.
- Secondary clustering increases search time.
- Separate chaining requires less memory than opening addressing.
- Separate chaining is an efficient way to resolve collisions.
Short Answer (7)
- Explain the two steps that typical hash functions perform.
- Assume you are using a hash function that takes strings and sums the Unicode values of each letter to create a hash code. Give an example of two strings that produce the same hash code.
- Assume the following hash function. Multiply the Unicode value of each character by a factor, g, based on the character’s position within the string. The hash code is the sum of these products.
u0gn-1 + u0gn-2 + … + un-2g + un-1
The Unicode value for uppercase ‘A’ = 65. Calculate the hash code for “ACE” with g = 7. - Assume the following hash function. Multiply the Unicode value of each character by a factor, g, based on the character’s position within the string. The hash code is the sum of these products.
u0gn-1 + u0gn-2 + … + un-2g + un-1
The Unicode value for uppercase ‘A’ = 65. Calculate the hash code for “FACE” with g = 7. - Assume you have a hash table length of 53. Given the value 216, what index will the entry map to?
- Assume you have a hash table length of 29. Given the value 371, what index will the entry map to?
- In open addressing with linear probing, explain why the remove method should not place null in the hash table.
Multiple Choice (28) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- The technique for determining an array index using only a search key and not searching is called
- hashing
- direct indexing
- search key indexing
- stealth searching
- When you use a search key to directly access an array without searching, the array is called a(n)
- hash table
- search array
- search table
- direct access array
- A(n) _____ takes a search key and produces the integer index of an element in a hash table.
- hash function
- search function
- transformation function
- black box
- A(n) _____ maps each search key into a different integer that is suitable as an index to the hash table.
- perfect hash function
- search key index
- hash index
- black box
- A hash function converts a search key into an integer called a(n)
- hash code
- key code
- search index
- ideal number
- When two search keys map to the same index, it is called a(n)
- collision
- duplicate mapping
- duplicate index
- index error
- Typical hash functions are not perfect because
- they allow more than one hash key to map to the same index
- they allow collisions
- both a & b
- none of the above
- A good hash function should
- minimize collisions
- be fast to compute
- distribute entries uniformly throughout the table
- all of the above
- To reduce the chance of a collision in a hash table
- distribute entries uniformly throughout the table
- use a Poisson distribution
- use a random number generator
- all of the above
- A search key can be
- a primitive data type
- an instance of a class
- both a & b
- none of the above
- The Java Object method hashCode returns
- an integer
- an Object
- a search key
- none of the above
- The Java Object method hashCode returns a value based on
- the memory address of the object used to invoke it
- a random number generator
- the memory address of the hash table
- the size of the hash table
- Duplicate hash code
- create collisions
- are necessary for a perfect hash table
- destroy the hash table
- all of the above
- If a search key’s data type is _____ you can use the key itself as the hash code.
- int
- float
- double
- String
- If a search key is an instance of _____ , it can be cast to an int to get a hash code.
- byte
- short
- char
- all of the above
- Dividing a long search key into pieces and combining them through addition or a bit-wise boolean operation is called
- folding
- combining
- optimizing
- hashing
- We want to distribute hash codes throughout the index range
- 0 through n-1
- 0 through n
- 1 through n-1
- 1 through n
- The recommended size of a hash table is a(n)
- prime number greater than 2
- Fibonacci number
- number that is a power of 2
- all of the above
- Finding an unused location in the hash table is called
- open addressing
- hash searching
- both a & b
- none of the above
- Resolving a collision in a hash table by examining consecutive locations in the table to find the next available one, beginning at the original hash index, is called
- linear probing
- open hashing
- hash walking
- collision resolution
- In open addressing with linear probing, what happens if the search key is not in the table?
- it depends on the implementation of the remove method
- the search probe sequence encounters a null location
- the search probe encounters an occupied marker
- it throws an exception
- In open addressing with linear probing, we must consider how to encode
- occupied positions
- empty positions
- available positions
- all of the above
- In open addressing, collisions that are resolved with linear probing cause groups of occupied consecutive locations in the hash table called
- clusters
- bundle
- collection
- hash knot
- In open addressing with linear probing, the increment is
- 1
- 2
- based on a secondary hash function
- j2
- Using a second hash function to compute increments for probe increments is called
- double hashing
- probe counting
- sequence hashing
- function hashing
- Given a hash function h(key) = key modulo 11, what index does the key 47 hash to?
- 3
- 5
- 7
- 1
- When each location of a hash table can represent more than one value, that location is called a(n)
- bucket
- open slot
- overloaded index
- linked slot
- Resolving collisions by using buckets that are linked chains is called
- separate chaining
- bucket chaining
- list resolution
- joint chaining
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano
Test Bank
General
View Product →
Explore recommendations drawn directly from what you're reading
Quick Navigation
Benefits
Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party