Hash Tables Linear Probing and Double Hashing

  • Thread starter Thread starter lina29
  • Start date Start date
  • Tags Tags
    Linear
AI Thread Summary
The discussion focuses on hashing keys using a hash table with 11 entries and the hash function h(x) = x mod 11, addressing collision resolution through linear probing and double hashing. Participants clarify that collisions occur when different keys yield the same hash value, exemplified by keys 10 and 43 both hashing to 10. The probing sequence for each key is determined based on whether the hash table is initially empty, with participants agreeing that the interval for linear probing is assumed to be 1. The conversation emphasizes the importance of understanding the initial state of the hash table when calculating probe sequences. Overall, the participants conclude that the approach to solving the problem is correct under the given assumptions.
lina29
Messages
84
Reaction score
0

Homework Statement


Consider a hash table T with 11 entries and the hash function h(x) = x mod 11. Show the result of hashing the keys 10,16,11,43,33,13,14,12,3, and 22, assuming collisions are handled by
(a) open addressing with linear probing
(b) double hashing using a secondary hash function h′(x) = 5−(x mod 5)


Homework Equations





The Attempt at a Solution



I believe I have the correct answer, I just want to double-check since I'm having difficulties.

Using a table I have:
Key ---- h(x) ---- h'(x) ---- probes LP ---- probes DH
10 ---- 10 ---- ---- 10 ---- 10
16 ---- 05 ---- ---- 5 ---- 5
11 ---- 00 ---- ---- 0 ---- 0
43 ---- 10 ---- 2 ---- 10, 0, 1 ---- 10,2
33 ---- 00 ---- 2 ---- 0, 1, 2 ---- 0, 2, 3
13 ---- 02 ---- 2 ---- 2,3 ---- 2,2,3,4
14 ---- 03 ---- 1 ---- 3,4 ---- 3,1
12 ---- 01 ---- 3 ---- 1,2,3,4,5,6 ---- 1,3,4,5,6
03 ---- 03 ---- 2 ---- 3,4,5,6,7 ---- 3,2,3,4,5,6,7
22 ---- 00 ---- 3 ---- 0,1,2,3,4,5,6,7,8 ---- 0,3,4,5,6,7,8
 
Physics news on Phys.org
The linear probe interval isn't specified. Are you supposed to assume it's 1? The contents of the hash table is not specified, so how are you supposed to know when collisions have occurred, or are you just supposed to list a set of indexes for the collision sequence for each key, or are you supposed to assume that the hash table is initially empty and the list of keys you're given are going to be stored in the hash table in the listed key order?
 
We're supposed to assume the interval is 1. I'm not sure I understand what you mean but you know a collision occurs when both keys have the same h(x) like keys 10 and 43 both have h(x) as 10
 
lina29 said:
We're supposed to assume the interval is 1. I'm not sure I understand what you mean but you know a collision occurs when both keys have the same h(x) like keys 10 and 43 both have h(x) as 10
I understand that, but are you just supposed to list the order in probes would take place if the hash table was completely filled (no empty slots), or are you supposed to list the probes that would take place if the hash table was initially empty and you stored that list of 10 keys into the hash table, leaving one empty slot when done?
 
Last edited:
We're supposed to list the probes by the place is should initially be at. if that spot is filled then we advance to the next spot until we find an empty spot
 
Looks like it's the case where you're adding those 10 keys in order to an initially empty table, in which case your answer appears to be correct. Note, you can put [ code ] and [ /code ] (without the spaces) around your text to preserve it's format.
 
thank you!
 

Similar threads

Replies
2
Views
1K
Replies
3
Views
2K
Replies
6
Views
2K
Replies
5
Views
3K
Replies
7
Views
2K
Back
Top