This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Hashing Functions”.

1. Which scheme uses a randomization approach?

a) hashing by division

b) hashing by multiplication

c) universal hashing

d) open addressing

View Answer

Explanation: Universal hashing scheme uses a randomization approach whereas hashing by division and hashing by multiplication are heuristic in nature.

2. Which hash function satisfies the condition of simple uniform hashing?

a) h(k) = lowerbound(km)

b) h(k)= upperbound(mk)

c) h(k)= lowerbound(k)

d) h(k)= upperbound(k)

View Answer

Explanation: If the keys are known to be random real numbers k independently and uniformly distributed in the range 0<=k<=1, the hash function which satisfies the condition of simple uniform hashing is

h(k)= lowerbound(km).

3. A good hash approach is to derive the hash value that is expected to be dependent of any patterns that might exist in the data.

a) True

b) False

View Answer

Explanation: A hash value is expected to be unrelated or independent of any patterns in the distribution of keys.

4. Interpret the given character string as an integer expressed in suitable radix notation.

Character string = pt

a) 14963

b) 14392

c) 12784

d) 14452

View Answer

Explanation: The given character string can be interpreted as (112,116) (Ascii values) then expressed as a radix-128 integer, hence the value is 112*128 + 116 = 14452.

5. What is the hash function used in the division method?

a) h(k) = k/m

b) h(k) = k mod m

c) h(k) = m/k

d) h(k) = m mod k

View Answer

Explanation: In division method for creating hash functions, k keys are mapped into one of m slots by taking the reminder of k divided by m.

6. What can be the value of m in the division method?

a) Any prime number

b) Any even number

c) 2^{p} – 1

d) 2^{p}

View Answer

Explanation: A prime number not too close to an exact power of 2 is often a good choice for m since it reduces the number of collisions which are likely to occur.

7. Which scheme provides good performance?

a) open addressing

b) universal hashing

c) hashing by division

d) hashing by multiplication

View Answer

Explanation: Universal hashing scheme provides better performance than other schemes because it uses a unique randomisation approach.

8. Using division method, in a given hash table of size 157, the key of value 172 be placed at position ____

a) 19

b) 72

c) 15

d) 17

View Answer

Explanation: The key 172 can be placed at position 15 by using the formula

H(k) = k mod m

H(k) = 172 mod 157

H(k) = 15.

9. How many steps are involved in creating a hash function using a multiplication method?

a) 1

b) 4

c) 3

d) 2

View Answer

Explanation: In multiplication method 2 steps are involved. First multiplying the key value by a constant. Then multiplying this value by m.

10. What is the hash function used in multiplication method?

a) h(k) = floor( m(kA mod 1))

b) h(k) = ceil( m(kA mod 1))

c) h(k) = floor(kA mod m)

d) h(k) = ceil( kA mod m)

View Answer

Explanation: The hash function can be computed by multiplying m with the fractional part of kA (kA mod 1) and then computing the floor value of the result.

11. What is the advantage of the multiplication method?

a) only 2 steps are involved

b) using constant

c) value of m not critical

d) simple multiplication

View Answer

Explanation: The value of m can be simply in powers of 2 since we can easily implement the function in most computers. m=2

^{p}where p is an integer.

12. What is the table size when the value of p is 7 in multiplication method of creating hash functions?

a) 14

b) 128

c) 49

d) 127

View Answer

Explanation: In multiplication method of creating hash functions the table size can be taken in integral powers of 2.

m = 2

^{p}

m= 2

^{7}

m = 128.

13. What is the value of h(k) for the key 123456?

Given: p=14, s=2654435769, w=32

a) 123

b) 456

c) 70

d) 67

View Answer

Explanation: A = s/2

^{w}

A = 2654435769/ 2

^{32}

k.A = 123456 * (2654435769/ 2

^{32})

= (76300 * 2

^{32}) + 17612864

Hence r1= 76300; r0=17612864

Since w=14 the 14 most significant bits of r0 yield the value of h(k) as 67.

14. What is the average retrieval time when n keys hash to the same slot?

a) Theta(n)

b) Theta(n^{2})

c) Theta(nlog n)

d) Big-Oh(n^{2})

View Answer

Explanation: The average retrieval time when n keys hash to the same slot is given by Theta(n) as the collision occurs in the hash table.

15. Collisions can be reduced by choosing a hash function randomly in a way that is independent of the keys that are actually to be stored.

a) True

b) False

View Answer

Explanation: Because of randomization, the algorithm can behave differently on each execution, providing good average case performance for any input.

**Sanfoundry Global Education & Learning Series – Data Structure.**

To practice all areas of Data Structure, __here is complete set of 1000+ Multiple Choice Questions and Answers__.

**If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]**

**Related Posts:**

- Practice Design & Analysis of Algorithms MCQ
- Check Data Structure Books
- Practice Programming MCQs
- Check Programming Books
- Check Computer Science Books