Set Depth : java.util.TreeMap

纵饮孤独 提交于 2019-12-11 09:13:02

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3690114/set-depth-java-util-treemap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!