Q: 1 Insert the characters of the string K R P C S T J M N Y into a hash table of size 10. Using the hash function h(x) = (ord(x)-ord(‘B’)+1) mod 10, and linear probing to resolve collisions, the final hash table is
(ord function returns ASCII value of the argument, for example : ord(‘A’) = 65)
K R P C S T J M N Y
B K P R S C T N Y M J
P S C K T Y N C J M
K J C M N P Y R S T
[ Option D ]
Hashing is a technique used to store data in a table using a hash function, which converts a key into an index. Sometimes, two keys may map to the same index, which is called a Collision.
To handle collisions, different collision resolution techniques are used:
In this question, linear probing is used, meaning if a slot is occupied, we move step-by-step to the next free slot.
The given hash function is, h(x)=(ord(x)-ord(′B′)+1) mod 10. Since ord('B')=66, the formula becomes:
| Character | ASCII | Calculation | Hash |
|---|---|---|---|
| K | 75 | (75-65)=10 : 10 mod 10 | 0 |
| R | 82 | (82-65)=17 : 17 mod 10 | 7 |
| P | 80 | (80-65)=15 : 15 mod 10 | 5 |
| C | 67 | (67-65)=2 : 2 mod 10 | 2 |
| S | 83 | (83-65)=18 : 18 mod 10 | 8 |
| T | 84 | (84-65)=19 : 19 mod 10 | 9 |
| J | 74 | (74-65)=9 : 9 mod 10 | 9 |
| M | 77 | (77-65)=12 : 12 mod 10 | 2 |
| N | 78 | (78-65)=13 : 13 mod 10 | 3 |
| Y | 89 | (89-65)=24 : 24 mod 10 | 4 |
Now Apply Linear Probing:
Final Hash Table:
| Index | Value |
|---|---|
| 0 | K |
| 1 | J |
| 2 | C |
| 3 | M |
| 4 | N |
| 5 | P |
| 6 | Y |
| 7 | R |
| 8 | S |
| 9 | T |
Therefore, Final Sequence : K J C M N P Y R S T
Q: 2 Which of the following data structures has search efficiency of O(1) always?
Tree
Heap
Hash Table
Linked List
[ Option C ]
Different data structures have different time complexities for searching. A Hash Table provides O(1) (Constant Time) search in the best and average case because it uses a hash function to directly compute the index where the data is stored, avoiding traversal.
Q: 3 A hash table H with 25 slots that maps 2400 elements has the load factor
80
96
64
48
[ Option B ]
In hashing, the Load Factor (α) represents how full a hash table is. It is defined as the ratio of the number of elements stored in the table to the total number of slots available. A higher load factor means more elements are stored per slot.
Load Factor = Number of Elements / Number of Slots
Here, number of elements = 2400 and number of slots = 25. So, Load Factor = 2400/25 = 96
Q: 4 Which data structure is typically used to implement hash table?
Linked List
Array
Binary Tree
Stack
[ Option B ]
A hash table is typically implemented using an array. The hash function converts a key into an array index, and the value is stored at that index in the array.
Arrays are used because they provide fast random access, which allows insertion, deletion, and searching operations in O(1) average time.
Q: 5 Which data structure is used for efficient searching, insertion, and deletion of elements?
Stack
Queue
Hash Table
More than one of the above
[ Option C ]
A Hash Table provides very fast searching, insertion, and deletion, generally in O(1) time on average, because it uses a hash function to compute the index of the element.
Hash Table stores data in an associative manner using a hash function to compute an index where the value is stored.
Q: 6 An advantage of chained hash table (external hashing) over the open addressing scheme is-
Worst case complexity of search operations is less
Space used is less
Deletion is easier
None of the above
[ Option C ]
In a chained hash table (external hashing), each slot in the hash table holds a linked list of all elements that hash to the same index. This makes deletion easier because elements can be removed from the linked list without affecting other entries in the main hash table array.
Unlike in open addressing, stores all elements directly in the array itself, which makes deletion more complex.
Another advantage of external hashing is it handles collisions efficiently, multiple elements can exist at the same slot without affecting other slots.
Q: 7 Consider the following two statements.
Statement -1 : A hash function may give the same hash value for distinct messages.
Statement -2 : A hash function takes a message of arbitrary length and generates a fixed length code.
Which of the following option is correct?
Both Statement-1 and Statement-2 are True
Both Statement-1 and Statement-2 are False
Statement-1 is True but Statement-2 is False
Statement-1 is False but Statement-2 is True
[ Option A ]
A Hash Function is used to convert input data (message) into a fixed-size value called a hash code. It is widely used in data structures and security applications.
Statement-1 is true because a hash function can produce the same hash value for different inputs, which is called a collision. Since the output size is fixed but input size can vary, collisions are possible.
Statement-2 is also true because a hash function takes input of arbitrary length and produces a fixed-length output i.e., 128-bit, 256-bit hash.
Q: 8 A hash function is defined as h(i) = i2 mod 8. What is the value of h(8)?
0
8
64
16
[ Option A ]
The given hash function is h(i)=i2 mod8. To find the value of h(8), we substitute i=8 into the function.
First, calculate 82=64. Then apply the modulus operation: 64 mod 8, which means finding the remainder when 64 is divided by 8.
Since 64 is exactly divisible by 8, the remainder is 0. Therefore, the value of the hash function is 0.
Q: 9 A hash table has space for 100 records. What is the probability of collision before the table is 10% full?
0.45
0.55
0.15
0.35
[ Option A ]
In a hash table with 100 slots, when 10 records are inserted (i.e., 10% full), the probability of no collision is calculated by multiplying the probabilities that each new record goes into a unique slot. This gives approximately 0.55.
Therefore, the probability of at least one collision is obtained by subtracting this from 1, i.e., 1-0.55 = 0.45. Hence, the probability of collision before the table is 10% full is 0.45.
Q: 10 Given a hash table with load factor of 300 that stores 10800 elements, the number of slots is?
36
299
301
63
[ Option A ]
The load factor (α) of a hash table is defined as the ratio of the number of stored elements (n) to the number of slots (m), that is
Load Factor (α) = Number of Elements (n) / Number of Slots (m)
Here, the load factor is 300 and the number of elements stored is 10800.
Therefore, Load Factor = 10800/300 = 36
Q: 11 Let hash function H(K) = (K mod 10) is employed to store in-order, the five keys [40, 27, 19, 48, 7] into set of single digit memory addresses (0-9). If linear probing is used to collision resolution, the key K=7 will be stored at which of the following location?
7
0
8
1
[ Option D ]
Given:
Step-by-step Insertion with Linear Probing:
Insert 40:
Insert 27:
Insert 19:
Insert 48:
Insert 7:
Use linear probing (check next available slot)
Try address 8 → Already taken (by 48)
Try address 9 → Already taken (by 19)
Try address 0 → Already taken (by 40)
Try address 1 → Free
So, 7 is stored at address 1
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.