문제

In a red-black tree with n nodes, what is the maximum number of red nodes (assuming the root is black)?

Is it O(n)?

도움이 되었습니까?

해결책

If the tree has n nodes and the root is black, there are n - 1 nodes left and n - 1 = O(n), so you're right.

If you want to count/bound number of red nodes in the tree more accurately, you have to know the topology of that tree.

For instance, if the tree is a complete binary tree, according to the definition of the red-black-tree, it can have no red nodes at all.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top