Top MCQs on Hash Data Strcuture with Answers

Last Updated :
Discuss
Comments

Question 1

Which of the following hash functions is most likely to cause clustering in a hash table? Here k is the input key value and m is hash table size. You may assume that all four hash functions generate valid indexes in the hash table.

  • h(k) = k % m

  • h(k) = floor(m * (k mod 1))

  • h(k) = k

  • h(k) = ((k / m) + k * m) + k % m

Question 2

What are the methods to handle  collision: 

  • Separate Chaining 

  • Open Chaining 

  • Both of the above

  • None of the above

Question 3

What are the applications of linear probing include:

  • Databases

  • Caching

  • Compiler Design

  • All of the above

Question 4

Which is a simple form of hashing where the data is directly mapped to an index in a hash table.

  • Collision

  • Index Mapping

  • Functional Mapping

  • Hash function

Question 5

Which of the following are components of Hashing?

  • Key

  • Hash Function

  • Hash Table

  • All of the above

Question 6

Output of given program is,

Python3
def findSymPairs(arr, row):
    hM = dict()
    for i in range(row):
        first = arr[i][0]
        sec = arr[i][1]
        if (sec in hM.keys() and hM[sec] == first):
            print("(", sec,",", first, ")")
        else:
            hM[first] = sec
        
if __name__ == '__main__':
    arr = [[0 for i in range(2)]
      for i in range(5)]
    arr[0][0], arr[0][1] = 11, 20
    arr[1][0], arr[1][1] = 30, 40
    arr[2][0], arr[2][1] = 5, 10
    arr[3][0], arr[3][1] = 40, 30
    arr[4][0], arr[4][1] = 10, 5
    findSymPairs(arr, 5)
  • (30, 40)
    (5, 10)

  • (30, 40)
    (5, 5)

  • (30, 4)
    (5, 1)

  • (3, 4)
    (5, 1)

Question 7

Suppose we are given n keys, m hash table slots, and two simple uniform hash functions h1 and h2. Further, suppose our hashing scheme uses h1 for the odd keys and h2 for the even keys. What is the expected number of keys in a slot? 

  • [Tex]\frac{n}{2m}[/Tex]

  • [Tex]\frac{n}{m}[/Tex]

  • [Tex]\frac{m}{n}[/Tex]

  • [Tex]\frac{2n}{m}[/Tex]

Question 8

A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below. 

 

Which one of the following choices gives a possible order in which the key values could have been inserted in the table?

  • 46, 42, 34, 52, 23, 33

  • 34, 42, 23, 52, 33, 46

  • 46, 34, 42, 23, 52, 33

  • 42, 46, 33, 23, 34, 52

Question 9

The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table?

 
  • A

  • B

  • C

  • D

Question 10

Consider a hash table of size seven, with starting index zero, and a hash function (7x+3) mod 4. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing ? Here “__” denotes an empty location in the table.
  • 3, 10, 1, 8, __ , __ , __
  • 1, 3, 8, 10, __ , __ , __
  • 1, __ , 3, __ , 8, __ , 10
  • 3, 10, __ , __ , 8, __ , __

There are 31 questions to complete.

Take a part in the ongoing discussion