1
I have encountered an interview question
「Implement a phone directory using Data Structures」
我希望它使用tries.By與試圖解決它來解決手機目錄,我試着用兩個嘗試,一個名字,另一個電話號碼, 但我面臨的一個困難。
想,我一定要添加三個條目(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.
:對於反向查找,它不會工作,這是從數量到name.For這一點,你必須創建另一個trie.If你包括值字段在特里還,那麼相同的值被存儲在twice.Once線索從從根到葉節點和其他時間在值字段中第二線索 – KIMchi
@KIMchi即完全正確的。所以你將有重疊,但你會得到在這兩種情況下 – Hani
快速搜索訪問:可以把它也可以不重複進行上有什麼建議? – KIMchi