Possible Duplicate:
storing 1 million phone numbers
How to design a data structure for a phone address book with 3 fields name, phone number , address
one must be able to search this phone book on any of the 3 fields
Hash table wouldn't work because all the three fields should hash to the same value which is i think impossible. I thought about trie and other data structures too but couldn't think of a proper answer.
Phone Directory can be efficiently implemented using Trie Data Structure. We insert all the contacts into Trie. Generally search query on a Trie is to determine whether the string is present or not in the trie, but in this case we are asked to find all the strings with each prefix of 'str'.
TRIE data structure is best suitable for a phone book.
Scanning refers to looking through a text very quickly to find specific details. For example, when we are searching for a telephone number in a directory, we scan the page for the name of the specific person we are looking for.
The answer is a bitarray or bit vector.
You Should use TRIE
data Structure for Implementing Phonebook. TRIE
is an ordered tree data structure that uses strings as keys. Unlike Binary Trees
, TRIE
does not store keys associated with the node.
Good example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With