Re: help with interview question



We can build two hash tables , one for lookup with phone number and
another for name.

May be you can try a hastable with N buckets where N is a positive
integer.
Each bucket will hold a AVL tree. Phone number will be used as key
for building AVL tree.

If you are going to lookup only on phone number (say P) then a
probable hash function will be:
P % N.
Then node containing phone number P will be stored in AVL tree located
at the index P % N.

You can have another hash table with M buckets. Each bucket will hold
a AVL tree.
Name should be used as key to build the AVL tree. This hashtable will
be used to do lookup by name.

Same structure information (like person,name, phone number ) will be
used for referencing in both the Hashtables/AVL tree
combination.

Can some one please comment out on the drawbacks of the above
algorithm,

- Krishnan

.



Relevant Pages

  • Re: Dictionary, hashing limitations
    ... Whenever I need a fast lookup table in C for keys that are not dense ... integers, I use a hash table, quite similar to the hash table used in ... and it has a fixed number of buckets. ... What kind of searchable structure optimized for the application's use ...
    (comp.lang.forth)
  • Re: half-avalanche and hashing
    ... that will hash a 32-bit integer well enough for table lookup, ... Does half-avalanche show up anywhere else? ... In addition to checking for half-avalanche, I eyeballed the buckets ...
    (comp.programming)
  • Re: Perl hashing speedup ?
    ... I feel that disbalanced bucket usage / and less number of hash buckets ... Now I have some queries regarding way perl hashing mechanism maps keys ... about how perl hashes work internally; but I guess we will be needing ...
    (comp.lang.perl.moderated)
  • Re: Hashing
    ... What you have to keep in mind is that a hash table for words in by ... linear testing of buckets. ... What is important is to ensure that you have an effective collision ... memory for the table, you need two arrays, one is the pointers to the ...
    (alt.lang.asm)
  • Re: Hash table in C++? STL?
    ... > a tree-like structure instead of lists for the buckets). ... > the standard will require equality or a relational comparator. ... the hashing function is where all the complexity lies and I'd be ... But we need hash only the first maxchars characters. ...
    (comp.lang.cpp)