Question

I sit with a piece of code of a T-tree index. A T-tree is a modified AVL-tree so that each node can hold many elements, as opposed to the AVL-tree, that can hold only 2 elements per node. The balancing requirements are the same, ie, there can only be a height difference of 1 among all leaf nodes of the tree. In other words, a T-tree is 'well balanced'. Each node of a T-tree can at most have 2 children: left and right, just as the nodes of an AVL-tree.

As opposed to a B-tree which have index nodes and leaf nodes, whre only the leaf nodes hold elements, a T-tree carries elements(or pointers to elements) in all its nodes.

How do I correctly calculate the height of a T-tree if each node can hold 350 element pointers and I have populated it with 1 000 000 elements?

Était-ce utile?

La solution

Calculate the height, when knowing the number of elements? It should be something like

 boolean greater = true;
 int i = 0;
 while(greater)
 {
    if(tree.lenght() <= 2^i)
       greater = false;
    i = i+1;
 }
 height = i;

But only if it is perfectly balanced.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top