电话簿的数据结构 [英] Data Structure for phone book
问题描述
可能重复:
存储100万个电话号码
如何设计数据具有三个字段
名称,电话号码,地址的电话簿的结构
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
哈希表不起作用,因为所有三个字段都应哈希为相同的值,我认为这是不可能的。我也考虑过trie和其他数据结构,但是想不出正确的答案。
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.
推荐答案
您应该使用<$ c用于实现电话簿的$ c> TRIE 数据结构。 TRIE
是使用字符串作为键的有序树数据结构。与二叉树
不同, TRIE
不存储与节点关联的密钥。
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.
这篇关于电话簿的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!