问题
I have read that it is log(n+1) <= h <= 2*log(n+1) where log is in base 2. However, when trying this out on a few known minimum heights, it does not always work out.
So far I know that:
For for h = 1, minimum # of nodes = 2.
For h = 2, minimum nodes = 4.
For h = 3, minimum nodes = 10.
However these were done purely by tracing it out using the rules for red-black trees.
Should I be taking note of the black-height when trying to find this or is my approach/calculations just completely wrong?
回答1:
We can find the minimal node count recursively.
count_minimum_node will return the number of nodes to achieve height h.
int count_node(int h)
{
int sum = h;
for(int i=1; i<=h-2; i++) sum += count_node(i);
return sum;
}
int count_minimum_node(int h) { return count_node(h+1); }
来源:https://stackoverflow.com/questions/42132204/what-is-the-formula-for-the-minimum-number-of-nodes-in-a-red-black-tree-of-heigh