In this Blog we are providing all the UGC-NET Computer Science previous year Questions with explanation:
Q: 2 A hash function f defined as f(key) = key mod 7, with linear probing it is used to insert the key 37,38,72,48,98,11,56 into a table index from 0 to 6. What will be the locations of 11 :
(A) 3
(B) 4
(C) 5
(D) 6
(UGC-NET Computer Science December 2004, December 2009)
Answer: (C)
Explanation: According to question f(key) = key mod 7. So, key will be inserted at after the result of key % 7. It will be 0,1,2,3,4,5 or 6. Because if we divide a number with 7 these are the possible remainders. Now in our given question the keys to be inserted are in order 37,38,72,48,98,11,56. Beginning with 37 it will be inserted at 37 % 7 = 2 i.e. location 2 in the table.
Next is 38, it will be inserted at 38 % 7 = 3 i.e. location 3 in the table.
Next is 72, it will be inserted at 72 % 7 = 2 but this location is already occupied by 37 So, by using linear probing we will examine next location which is 3 but it is also occupied by 38 So, we will examine next location which is 4 and it is empty hence 72 will be inserted at location 4 in the table.
Next is 48, it will be inserted at 48 % 7 = 6 i.e. location 6 in the table.
Next is 98, it will be inserted at 98 % 7 = 0 i.e. location 0 in the table.
Next is 11, it will be inserted at 11 % 7 = 4 but this location is already occupied by 72 So, we will examine next location which is 5 and also empty so 11 will be inserted at location 5 in the table.
Next is 56, it will be inserted at 56 % 7 = 0 but this location is already occupied So by linear probing method it will be inserted at next location i.e. 1.
The table will look like this after all keys are inserted.
Q: 2 A hash function f defined as f(key) = key mod 7, with linear probing it is used to insert the key 37,38,72,48,98,11,56 into a table index from 0 to 6. What will be the locations of 11 :
(A) 3
(B) 4
(C) 5
(D) 6
(UGC-NET Computer Science December 2004, December 2009)
Answer: (C)
Explanation: According to question f(key) = key mod 7. So, key will be inserted at after the result of key % 7. It will be 0,1,2,3,4,5 or 6. Because if we divide a number with 7 these are the possible remainders. Now in our given question the keys to be inserted are in order 37,38,72,48,98,11,56. Beginning with 37 it will be inserted at 37 % 7 = 2 i.e. location 2 in the table.
Next is 38, it will be inserted at 38 % 7 = 3 i.e. location 3 in the table.
Next is 72, it will be inserted at 72 % 7 = 2 but this location is already occupied by 37 So, by using linear probing we will examine next location which is 3 but it is also occupied by 38 So, we will examine next location which is 4 and it is empty hence 72 will be inserted at location 4 in the table.
Next is 48, it will be inserted at 48 % 7 = 6 i.e. location 6 in the table.
Next is 98, it will be inserted at 98 % 7 = 0 i.e. location 0 in the table.
Next is 11, it will be inserted at 11 % 7 = 4 but this location is already occupied by 72 So, we will examine next location which is 5 and also empty so 11 will be inserted at location 5 in the table.
Next is 56, it will be inserted at 56 % 7 = 0 but this location is already occupied So by linear probing method it will be inserted at next location i.e. 1.
The table will look like this after all keys are inserted.
98 | 56 | 37 | 38 | 72 | 11 | 48 |
---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | 6 |
No comments:
Post a Comment