设置深度:java.util.TreeMap
我们如何设置 TreeMap 对象的深度。 假设我们试图在 TreeMap 的底层数据结构之上构建自动建议功能,我们知道树的深度会如何影响性能?
How can we set depth of a TreeMap object.
Suppose we are trying to build an auto suggest feature on top of underlying data structure of a TreeMap, how would depth of a tree as we know affect the performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题很模糊,但如果我理解正确的话,你就误解了概念。 TreeMap 是 Map 接口的实现,它使用红黑树将其内容按自然升序排序,而您所要求的是完全不相关的东西;根据项目在图表中的位置对项目进行排名。
Your question is vague but if I understand correctly, you're misunderstanding concepts. TreeMap is an implementation of the Map interface which uses red-black tree for sorting its contents into natural ascending order while what you're asking is something completely unrelated; ranking items based on their position in a graph.
您无法直接设置 TreeMap 的(最大)深度,甚至无法精确确定其深度。然而,在最好和最坏的情况下,深度将大约
ceiling(log2(table.size()))
。平均查找时间与树中叶节点的平均深度成正比。
You cannot directly set the (maximum) depth of a TreeMap, or even precisely determine what its depth is. However, the depth will be approximately
ceiling(log2(table.size()))
in the best and worst case.The average lookup time will be proportional to the average depth of leaf nodes in the tree.