当前位置: 动力学知识库 > 问答 > 编程问答 >

algorithm - Best way to store contacts in Phone

问题描述:

It is basically an Interview question .

What is the best Data-Structure to be employed to store phone-numbers/Contact names in a phone directory . We should be able to retrieve number from name and vice-versa.

Few solutions i've heard of :

1. Create 2 Hashmaps , one maps number to name,other name to number.

2. Create 2 Tries . Uses lesser memory than above.

What better can be done for it , Talking mainly about Space complexity .

网友答案:

I think using 2 tries is the best option, space comlexity wise. Because once you have a hash table, you'll have to handle collisions.

分享给朋友:
您可能感兴趣的文章:
随机阅读: