The Student Room Group

CompSci Hash Tables?!?!

Hey all, I'm self studying A level computer science, but this is one topic I'm struggling to get my head around, hash tables. Here is the question I am on:

Q) Using the hashing function k(k+3) mod m, where k is the key field and m is the bucket size, if m is 251, calculate the addresses for the key fields:
a) 101
b)52

Now I understand you substitute the key field into k and 251 into m e.g. for a) 101((101+3) = 104) mod 251
=10504 mod 251
But from here I'm not sure on what I'm doing. I've done my best to try to understand the use of modular arithmetic, but I don't know how to do these questions. Can anyone help me out? Thank you in advance (the answers are 213 for a) and 99 for b) btw)
the mod operator shows you the remainder of number you divide. for example: 7 mod 3 = 1 (7-3-3, remainder is 1) or 5 mod 2 = 1(5-2-2, remainder is 1), but 15 mod 3 = 0 (remainder equals 0: 15-3-3-3-3-3).

in your case, you put the numbers 101 and 53 instead of 'k' and find the remainder by dividing on 251. so its ( 101*(101+3)) mod 251.

you can also Google any number and find the remainder. just type "number mod number". try to predict the result and then you shall get how it works
(edited 6 years ago)
Reply 2
Original post by JustVladon
the mod operator which shows you the remainder of number you divide. for example: 7 mod 3 = 1 (7-3-3, remainder is 1) or 5 mod 2 = 1(5-2-2, remainder is 1), but 15 mod 3 = 0 (remainder is equals 0: 15-3-3-3-3-3).

in your case you put the numbers 101 and 53 instead of 'k' and find the remainder by dividing on 251. so its ( 101*(101+3)) mod 251.

you can also Google any number and find the remainder. just type "number mod number". try to predict the result and the you shall get how it works


Thank you Vladon, I think I understand the concept better now. Is there a reputation or something I can give to you?
Original post by AR12
Thank you Vladon, I think I understand the concept better now. Is there a reputation or something I can give to you?


no worries, i dont need anything :wink:

Quick Reply

Latest