tags:

views:

72

answers:

2

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  A: 

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.

Esko
A: 

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.

Stephen C
IIRC, in a red-black tree, the depth can be up to 2*log2(size).
Michael Borgwardt