Question

In: Computer Science

For the division method for creating hash functions, map a key k into one of m...

For the division method for creating hash functions,
map a key k into one of m slots by taking the remainder of k divided by m. The hash function is:
       h(k) = k mod m,
    where m should not be a power of 2.
For the Multiplication method for creating hash functions,
    The hash function is h(k) = └ m(kA –└ k A ┘) ┘ = └ m(k A mod 1) ┘
   where “k A mod 1” means the fractional part of k A; and a constant A in the range
0 < A < 1.
An advantage of the multiplication method is that the value of m is not critical.
Choose m = 2p for some integer p.
Give your explanations for the following questions:
(1) why m should not be a power of 2 in the division method for creating hash function; and
    (2) why m = 2p, for some integer p, could be (and in fact, favorably) used.

Solutions

Expert Solution

Division method

In Hash function, the key must be transformed into integer. The value is to be in between 0-(m-1).

Example:

hash table has size m = 12 , the key is k = 100, then h(k) = 4. it require only single division operation so it is quite fast.

m should not be a power of 2 (m = 2p)

h(k) is the p lowest-order bits of k.

probability distribution on keys makes all low-order p-bit patterns equally likely, it is better that the hash function depend on all the bits of the key.

the value of m should not be close to the exact power of 2.

multiplication method

multiplication method for creating hash functions.

multiply key k by a constant A (range 0 < A < 1) . Then, we multiply this value by m .

In short, the hash function is

h(k) = ⌊m(kA mod 1)⌋,

the value of A should not be close to 0 or 1.

the value of m is not critical. choose m = 2p.

Example:

Knuth says good value for A is 0.618033

k = 123456, m = 10000,

h(k) = 10000 (123456 * 0.61803 mod 1) = 10000 (76300.00411mod 1)

= 41.151 = 41


Related Solutions

Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key)...
Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key) = (16 - (key % 10)) + 1 to insert the following numbers into a dictionary's hash table: 1, 12, 14, 3, 5 and 17. The table size is 11. Show the table and where each value is inserted. No coding required for this problem.
In java. Write a method static <K, V> void addToMultiMap(Map<K, Set<V>> map, K key, V value)....
In java. Write a method static <K, V> void addToMultiMap(Map<K, Set<V>> map, K key, V value). addToMultiMap must add the value, if present, to the set associated with the given key, creating the set if necessary. You may assume all keys already in the map are associated with non-null values. For full credit, your method must include generic types, and must not contain unnecessary method calls or loops, even if they do not otherwise impact correctness. You may assume Map,...
Discuss in detail at least one of the key network functions.
Discuss in detail at least one of the key network functions.
Provide one or two sentence descriptions to indicate the key functions of the following hematopoietic and...
Provide one or two sentence descriptions to indicate the key functions of the following hematopoietic and lymphoid organs/tissues: A. Bone marrow B. Thymus C. Spleen D. Lymph nodes E. MALT
3) A stock sells for 75. Using the M-K method, what is the standard deviation of...
3) A stock sells for 75. Using the M-K method, what is the standard deviation of this stock if a six month call option at 70 sells for 8.06 when the interest rate is 3.5?
Q1 (a) If k(x,y) and l(x,y) are 2 utility functions and are quasiconcave then show m(x,y)=min...
Q1 (a) If k(x,y) and l(x,y) are 2 utility functions and are quasiconcave then show m(x,y)=min (k(x,y,),l(x,y) is also quasiconcave. (b) Show that k(x,y) is strictly quasiconcave if and only if the preference relation (>~) is strictly convex.
4. A spring with k=45 N/m is oriented vertically with one end fixed to the ground....
4. A spring with k=45 N/m is oriented vertically with one end fixed to the ground. A 0.5 kg mass on top of the spring compresses it. 
 Provide a conceptual explanation of what is happing for each of the following cases a. You hold the mass while you gently compress the spring, and when you release the mass it sits at rest atop the spring. b. You place the mass on the uncompressed spring and release it. c. You drop...
Write a Python program to implement one studied entropy coding method, including two separate functions for...
Write a Python program to implement one studied entropy coding method, including two separate functions for encoding and decoding. Use the lyrics of your favorite song as the message to be processed, and test the program on the message. Include the source code, and detail the program design and execution procedure in this section.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT