In UG Boys Hostel Having 5 floors and each floor having 15 rooms. Consider you have to allocate the hostel room for students of IT department using hashing techniques (Hint: Key=201IT253). For only final year, one student per room and all other rooms are shareable at the maximum of three students per room. You may to use any strategy but must implement the separate chaining and Linear probing techniques in your solution.
SOLUTION TO THE ABOVE QUESTION
For the purpose of understanding lets take only one floor with 15 rooms.
Lets the rollno of Final year students be 16, 21, 23, 31
Lets the rollno of 1st year student be 19, 34, 49.
Now when we start providing room to Final year student then we can put only one student in a room and in case of 1st year student, we can keep 3 students in a room.
For student with Rollno 16 -> 16 % 15 = 1 ( room no. 1 is provided to him)
For student with Rollno 21 -> 21 % 15 = 6 ( room no. 6 is provided to him)
For student with Rollno 23 -> 23 % 15 = 8 (room no. 8 is provided to him)
For student with Rollno 31 -> 31 % 15= 1 (since room no. 1 is occupied by a final year student, we have to provide the next empty room to student(roollno 31), this is called linear probing )
For 1st year student with rollno 19 -> 19 % 15 = 4 ( room no. 4 is provided to him)
For 1st year student with rollno 34 -> 34 % 15 = 4 (since it is 1st year student, so we can provide the same room untill 3 students are their, it will cause chaining. )
For 1st year student with rollno 49 -> 49 % 15 = 4 (since it is 1st year student, so we can provide the same room untill 3 students are their, it will cause chaining. )
Comments
Leave a comment