1

In linear probing there is a special value called AVAILABLE which is replaced when items are removed.

And when you are inserting a key you look for a empty cell (this just means the cell is null?) or one that contains AVAILABLE, what I don't understand is if the empty cell means null instead of having the special value AVAILABLE why not just make the cell null?

What is the advantage over using AVAILABLE?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
orange
  • 5,297
  • 12
  • 50
  • 71
  • Can you give a reference to where you got the "AVAILABLE" term? Maybe it is a quirk from academia. – usr Apr 24 '12 at 20:41
  • @usr yes, [here](http://www.cs.sfu.ca/CC/225/jmanuch/lec/12-3.ppt) it is on slide 10, the comments on the code – orange Apr 24 '12 at 21:10
  • Hm I have no idea. At least according to the code shown null and AVAILABLE are equivalent. – usr Apr 24 '12 at 21:34

1 Answers1

2

In closed hashing (open addressing) a value is looked up as:

  1. Compute key hash and from it determine the "perfect" bucket;
  2. If the bucket is occupied and has key equal to the one looked up, return the value;
  3. If the bucket is not occupied, abort the lookup with a failure;
  4. Go to the next bucket (with linear probing just increment bucket index) and step 2.

Now, suppose you start looking up in bucket 5 and find your key only in bucket 8. If erasing procedure now marked bucket 6 as unoccupied, you'd never get to bucket 8 due to step 3. Therefore, we need a special value that marks bucket as "occupied", yet still available for insertion. This is probably what your source terms as AVAILABLE, and null as unoccupied at all.

EDIT: BTW, with linear probing it is possible to (quite) efficiently get away without this special AVAILABLE value, but that complicates erasing considerably.