【发布时间】:2016-07-20 23:37:34
【问题描述】:
I have encountered an interview question
“Implement a phone directory using Data Structures”
我想通过尝试解决它。通过尝试解决它,我尝试使用两次尝试,一个用于姓名,另一个用于电话号码,
但我遇到了困难。
假设,我必须添加三个条目(AB “112” BC “124” CD “225”)
那么如果我查询名称为“225”,我如何返回CD。
也就是这两个尝试如何联系起来。
One approach I was thinking was taking two pointers in both the tries.
These pointers will point to the first and last word in the other trie.
For example,if the structures are as follows:
Struct nametrie
{
Struct nametrie *child[26];
struct phonetrie*head,*tail;
struct phonetrie*root;
-----------
}
Struct phonetrie
{
struct phonetrie*child[9];
struct nametrie*head,*tail;
struct nametrie*root;
-----------
}
Then for AB “112”,
Name trie willstore head(1) and tail (2).
但我认为这种方法不适用于重复条目(一个名称和多个数字。)
Can someone please explain a good approach.I am not looking for code but good understanding of approach,may be via diagram or algorithm.
【问题讨论】: