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?

This question was previously asked in
UGC NET Computer Science (Paper 2) July 2018 Paper
View all UGC NET Papers >
  1. 3
  2. 4
  3. 5
  4. 6

Answer (Detailed Solution Below)

Option 3 : 5
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
8.8 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

Concept:

Hashing is used to uniformly distribute key values into the table using a hash function. In linear probing, when allocating location to the key values, if there occurs a collision, then we linearly probe for the next vacant location and allocate that to the key.

Explanation:

Hash function: h(key) = key mod 7

Keys are 44, 45, 79, 55, 91, 18, 63

Table size = 7( 0 to 6)

index 0 1 2 3 4 5 6

key

 

 

 

 

 

 

 

 

Step 1: key is 44 , h(44) = 44 mod 7 = 2,

Key 44 will move into index 2.

index 0 1 2 3 4 5 6

key

 

 

44

 

 

 

 

 

Step 2: Next 45, h(45)= 45 mod 7 = 3

45 will move to index 3.

index 0 1 2 3 4 5 6

key

 

 

44

45

 

 

 

 

Step 3: key 79, h(79) = 79 mod 7 = 2 (collision as, there is already a key value at index 2).

So, 79 will go for the next empty location, i.e. 4

index 0 1 2 3 4 5 6
key

 

 

44

45

79

 

 

 

Step 4: next key is 55, h(55) = 55 mod 7 = 6,

Key 55 will go into index 6.

index 0 1 2 3 4 5 6
key

 

 

44

45

79

 

55

 

Step 5: key 91, h(91) = 91 mod 7 = 0

index 0 1 2 3 4 5 6
key

91

 

44

45

79

 

55

 

Step 6: key 18, h(18) = 18 mod 7 = 4 (collision , move to next empty location i.e. 5)

index 0 1 2 3 4 5 6
key

91

 

44

45

79

18

55

 

Step 7: key 63, h(63) = 63 mod 7 = 0 (due to collision, it will move into index 1)

index 0 1 2 3 4 5 6
key

91

63

44

45

79

18

55

 

Therefore, the location of 18 elements is 5

Latest UGC NET Updates

Last updated on Jun 6, 2025

-> The UGC NET Exam Schedule 2025 for June has been released on its official website.

-> The UGC NET Application Correction Window 2025 is available from 14th May to 15th May 2025.

-> The UGC NET 2025 online application form submission closed on 12th May 2025.

-> The June 2025 Exam will be conducted from 21st June to 30th June 2025

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

More Hashing Questions

Get Free Access Now
Hot Links: teen patti list teen patti winner teen patti game - 3patti poker teen patti 51 bonus teen patti real money app