PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] Storing the key in the hash table
Date: Tuesday, 14 Apr 2020, 19:15:02


    > Message Posted By: Unknown
    >
    > i'm a bit confused generally as to why we need to store the key in the
    > hash table. ...

Many different keys, each with its own attribute, could
map to each bucket.  If you did not store the keys, how
could you know which were were mapped?
=====

    >         ... if we wanted to insert, we would feed the key to the hash
    > funtion (which in our case is POSITION) to get the location where  we have
    > to search. ...

Correct, but for what are you searching if you do not
store the keys?
=====

    >       ...  To lookup, we would also feed the key to the hash function to
    > get where in the hash table the value we are looking for is. ...

Correct if the item is in the table and is the only item
mapped to this bucket, but what if it is not in the table
or is not the only item?
=====

    >                                                         ...  Why then do
    > we also store the key in the locations (if my understanding of the
    > functions i've explained is right)?

See above.  I suggest that you read Apnes' notes on hashing,
watch the walk-through, go to office hours, and/or make an
appointment to meet with me.

--Stan-
PREV INDEX NEXT