开发者

Set Depth : java.util.TreeMap

How can we set depth of a TreeMap object. Supp开发者_如何转开发ose 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜