CPSC 461: Copyright © 2002 Katrin Becker 1998-2002 Last Modified November 14, 2002 03:27 PM

Hashing: Collision Resolution: Computed Chaining [1]

Record Keys: 27, 18, 29, 28, 39, 13, 16, 38, 53

Table Size = 11; Hash Function = hash(key) = key mod 11

Incrementing Function = i(key) = Quotient (Key / 11) mod 11 (computed on resident key)

(nof = number of offsets)

 
Key
nof
 
0
     
1
     
2
     
3
     
4
     
5
27
  1. 27 mod 11 = 5
6
28
2
4. 28 mod 11 = 6; 5. h(39) = 6; i(28) = 2; goto 8 then 10
7
18
1
2. 18 mod 11 = 7; 3. 29 mod 11 = 7; i(18) = 1 so goto 8
8
29
   
9
     
10
39
   

Note that the number of offsets indicates what to multiply i(key) by to find the next record in the chain. To find 28, (18/11) mod 11 = 1 mod 11; offset is 1; number of offsets is one so the record is at address 8. To find 39, (28/11) mod 11 = 2 mod 11; offset = 2, loc8 is occupied so try 10. It works so the number of offsets stored in the predecessor’s pseudolink is 2.

 
Key
nof
 
0
     
1
     
2
13
  6. 13 mod 11 = 2
3
     
4
     
5
27
2
7. 16 mod 11 = 5; i(27) = 2; goto 7 then 9; 8. 38 mod 11 = 5; but 27
6
28
2
already has a successor so go there (1 seek); it has no successor;
7
18
1
use i(16) = 1 to go to loc10; it's occupied so wrap around to loc0;
8
29
  insert 38 at loc0; update 16's pseudolink to 2
9
16
   
10
39
   


 
Key
nof
 
0
38
   
1
     
2
13
   
3
     
4
     
5
27
2
 
6
28
2
 
7
18
1
 
8
29
   
9
16
2
9. h(53) = 9; since h(16) = 5; 16 is not at its home address, we need to
10
39
  do some moving. Move 16 and ALL its successors.

16 has a successor so we must find it. Remove and save 16 and 38; update pseudolink for 27. Now put 53 where it belongs so there will only be 1 probe for it. Then re-insert 16 and 38.

 
Key
nof
SAVE 16 and 38
0
16
1
 
1
38
   
2
13
   
3
     
4
     
5
27
3
9A. h(16) = 5; i(27) = 2; goto 7,9,0 and insert; 3 offsets
6
28
2
9B. h(38) = 5; follow links to loc0; i(16) = 1; goto 1 and insert
7
18
1
 
8
29
   
9
53
   
10
39
   

Variation: we can cut down the number of searches considerably by creating multiple chains.

We need a way to decide which chain to follow based on the key we are looking for. One simple method is to use one chain for even keys and another for odd keys. We need to add another pseudolink field but the extra space may not be as important as the reduced search time. Now what we do when we get to the start of a chain is to follow pseudolink0 if the probe key is even ((probekey mod 2)=0) and psudolink1 if the probe key is odd ((probekey mod 2) = 1). When keys need to be moved only one pseudolink chain is affected.


Back to Top
CPSC 461: Copyright © 2002 Katrin Becker 1998-2002 Last Modified November 14, 2002 03:27 PM