Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Structure for phone book [duplicate]

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.

like image 561
Anusha Pachunuri Avatar asked Feb 02 '12 05:02

Anusha Pachunuri


People also ask

Which data structure is used in phone book?

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'.

Which STL is best for a phone book?

TRIE data structure is best suitable for a phone book.

What process will you go through when you are looking up a name in the 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.

How will you store a series of mobile number in memory efficiently less space?

The answer is a bitarray or bit vector.


1 Answers

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

like image 98
Raj Avatar answered Sep 19 '22 17:09

Raj