wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Hashing

Total questions: 20

Worksheet time: 18mins

Name
Class
Date
1.
Which data structure uses hashing to store information with constant lookup time?
a)
Hash table
b)
1D Array
c)
Linked List
d)
2D Array
e)
Stack
2.

What is the load factor?

a)

Average array size

b)

Average key size

c)

Average chain length

d)

Average hash table length

3.

In simple chaining, what data structure is appropriate?

a)

Singly linked list

b)

Doubly linked list

c)

Circular linked list

d)

Binary trees

4.

The case in which a key other than the desired one is kept at the identified location is called?

a)

Hashing

b)

Collision

c)

Chaining

d)

Open addressing

5.

Which of the following is not a collision resolution technique?

a)

Separate chaining

b)

Linear probing

c)

Quadratic probing

d)

Hashing

6.

Hashing is not the problem of finding an appropriate mapping of keys into addresses.

a)

True

b)

False

7.

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 above.


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

a)

46, 42, 34, 52, 23, 33

b)

34, 42, 23, 52, 33, 46

c)

46, 34, 42, 23, 52, 33

d)

42, 46, 33, 23, 34, 52

8.

Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020?

a)

h(i) =i^2 mod 10

b)

h(i) =i^3 mod 10

c)

h(i) = (11 ∗ i^2) mod 10

d)

h(i) = (12 ∗ i) mod 10

9.

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true?

i. 9679, 1989, 4199 hash to the same value

ii. 1471, 6171 has to the same value

iii. All elements hash to the same value

iv. Each element hashes to a different value

a)

i only

b)

ii only

c)

i and ii only

d)

iii or iv

10.

What is the worst case search time of a hashing using separate chaining algorithm?

a)

O(N log N)

b)

O(N)

c)

O(N^2)

d)

O(N^3)

11.

What is the advantage of using a doubly linked list for chaining over singly linked list?

a)

it takes less memory

b)

it is easy to implement

c)

it makes the process of insertion and deletion faster

d)

it causes less collisions

12.

Separate chaining is easier to implement as compared to open addressing .

a)

True

b)

False

13.

In open addressing the hash table can never become full.

a)

True

b)

False

14.

Which of the following trait of a hash function is most desirable?

a)

it should cause less collisions

b)

it should cause more collisions

c)

it should occupy less space

d)

it should be easy to implement

15.

Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is

a)

80

b)

0.0125

c)

8000

d)

1.25

16.

Which of the following statement(s) is TRUE?

1) A hash function takes a message of arbitrary length and generates a fixed length code.

2) A hash function takes a message of fixed length and generates a code of variable length.

3) A hash function may give the same hash value for distinct messages.

a)

1 only

b)

1 & 3 only

c)

2 & 3 only

d)

3 only

17.

A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed from 0 to 6. What will be the location of key 18?

a)

3

b)

4

c)

5

d)

6

18.

A hash table with ten buckets with one slot per bucket is shown in the following figure. The symbols S1 to S7 initially entered using a hashing function with linear probing.The maximum number of comparisons needed in searching an item that is not present is

a)

3

b)

4

c)

5

d)

6

19.

The characters of the string K R P C S N Y T J M are inserted into a hash table of size 10 using hash function

h(x) = ((ord(x) - ord(A) + 1)) mod 10

(here ord(A) = 1, ord(B)=2, so on)

If linear probing is used to resolve collisions, then the following insertion causes collision

a)

Y

b)

C

c)

M

d)

P

20.

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)

A

b)

B

c)

C

d)

D