设置深度:java.util.TreeMap

发布于 2024-09-18 15:45:23 字数 79 浏览 0 评论 0原文

我们如何设置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叶落知秋 2024-09-25 15:45:23

你的问题很模糊,但如果我理解正确的话,你就误解了概念。 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.

記柔刀 2024-09-25 15:45:23

我们如何设置 TreeMap 对象的深度。

您无法直接设置 TreeMap 的(最大)深度,甚至无法精确确定其深度。然而,在最好和最坏的情况下,深度将大约 ceiling(log2(table.size()))

假设我们试图在 TreeMap 的底层数据结构之上构建自动建议功能,我们知道树的深度会如何影响性能?

平均查找时间与树中叶节点的平均深度成正比。

How can we set depth of a TreeMap object.

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.

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?

The average lookup time will be proportional to the average depth of leaf nodes in the tree.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文