Thanks all for help.

On Jan 8, 6:07 pm, me13013 <[email protected]> wrote:
> On Jan 7, 10:10 am, Vijay <[email protected]> wrote:
>
>
>
>
>
> > Can you please tell me what will be the contains of Hash table and how
> > searching works?
>
> > Lets say, we have one data like
> > Key       Data
> > ===========
> > IP1 -  Sys1
> > IP8    Sys8
> > IP2    Sys2
>
> > Lets say, there are keys  "IP1" and "IP8". and Hash_function will
> > return 1 as index for both so collision occurred. And Hash_insert
> > will
> > insert "Sys2" at index 3 as 2 is already filled.
>
> > I understand, Hash Table will have index (got from Hash_function) and
> > corresponding data
>
> > HashTable[index][data] ->
> > [1]["Sys1"]
> > [2]["Sys8"]
> > [3]["Sys2"]
>
> > Lets say we have searching/lookup function data_type GetData(key)
> > which will take key and return correct data from table HashTable[index]
> > [data]. Searching/lookup function will find index from key using
> > Hash_function. And Hash_function will return duplicate index. then how
> > it will locate correct data?
>
> Your table should be an array of key-value pairs.  Relating this to
> your example, you would have
> HashTable[index][data] ->
> [1]["IP1","Sys1"]
> [2]["IP8","Sys8"]
> [3]["IP2","Sys2"]
>
> Now when you do a query for "IP8", you hash "IP8" to the index 1.  You
> compare "IP8" to the key at index 1.  That key is "IP1", so linear
> probing (I assume that's the right name for it) then increments the
> index and compares "IP8" to the next key.  In this case it sees "IP8"
> and then can report the value for that key, "Sys8", as the result of
> the query.
>
> HTH, Bob H
-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.


Reply via email to