MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Why do hashing algorithms use the MOD function?
A
produces a random value
B
guarantees the value is in range
C
avoids collisions
D
can work on both integers and chars
Explanation: 

Detailed explanation-1: -we use % (modulo) in hashing to calculate remainder of a division(our data % chosen number). if our mod be a prime number which also is our divisor it is more likely that division has a remainder and less numbers has same factor like our divisor So less collision happens.

Detailed explanation-2: -A good hash function to use with integer key values is the mid-square method. The mid-square method squares the key value, and then takes out the middle r bits of the result, giving a value in the range 0 to 2r−1. This works well because most or all bits of the key value contribute to the result.

Detailed explanation-3: -For hashing, prime numbers are used since they provide a better chance of creating unique values for a hash function.

Detailed explanation-4: -With modular hashing, the hash function is simply h(k) = k mod m for some m (usually, the number of buckets). The value k is an integer hash code generated from the key. If m is a power of two (i.e., m=2p), then h(k) is just the p lowest-order bits of k.

There is 1 question to complete.