简体   繁体   English

将Trie扩展到更多的叶子

[英]Extending trie to higher number of leaves

I have to make a dictionary using tries, the number of letters in the alphabet will increase from 26 to 120, and hence the numb er of leaf nodes will increase exponentially. 我必须使用尝试来制作字典,字母表中字母的数量将从26增加到120,因此叶节点的数量将成倍增加。 What optimisations can I use so that my lookup, insertion and deletion time doesn't increase exponentially? 我可以使用哪些优化来使我的查找,插入和删除时间不成倍增加?

EDIT Making the question clearer, sorry for the lack of details I am using a multiway trie like radix tree and making some modifications to it. 编辑让问题更清楚,对不起缺少细节,我使用的是基数树之类的多路Trie并对其进行了一些修改。 My question is if I know that the word size will increase (for sure) from 26 to 120, it will increase the depth of the tree. 我的问题是,如果我知道单词的大小(肯定)将从26增加到120,那么它将增加树的深度。 Is it possible to decrease the increase in depth by increasing the key to more than 64 bits (the register can gold maximum 64 bits)? 是否可以通过将密钥增加到64位以上来减少深度的增加(寄存器最多可以容纳64位)?

It's often better to use binary tries with path compression (Patricia tries) based on the binary representation of your keys. 通常,最好基于密钥的二进制表示形式对路径压缩使用二进制尝试(Patricia尝试)。 That way you get the benefits of the smallest possible alphabet, and you still only have 2 nodes (one leaf and one internal) per key. 这样,您可以获得尽可能小的字母的好处,并且每个键仍然只有2个节点(一个叶子和一个内部)。

Though there may be some optimizations otherwise but our lookup, insertion and deletion time will not increase exponentially. 尽管否则可能会有一些优化,但是我们的查找,插入和删除时间不会成倍增加。 Increasing your alphabet set only means that your each trie node will be bigger now. 增加字母集仅意味着您的每个trie节点现在都会更大。 The path to each word will still have the same length which is equal to the letters in the word. 每个单词的路径仍将具有与单词中的字母相同的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM