Professional Documents
Culture Documents
Height and Weight Balanced Trees
Height and Weight Balanced Trees
1 Height-Balanced Trees
3.2 Weight-Balanced Trees
Chen Song
Height-Balanced Trees
Height-Balanced Trees
Height-Balanced Tree –
In each interior node, the height of the right
subtree and left subtree differ by at most one.
Height-Balanced Trees
Example:
Height-Balanced Trees
Theorem
A height-balanced tree of height h has at least
3+ 5 1+ 5 ℎ 3− 5 1− 5 ℎ
( )( ) −( )( )
2 5 2 2 5 2
leaves.
Height-Balanced Trees
Tree T
h-2
h-1
Weight –
The number of leaves of a tree.
Weight-Balanced Tree –
The weight of the right and left subtree in each
node differ by at most one.
Weight-Balanced Trees
α-weight-balanced trees
For each subtree, the left and right sub-subtrees has
each at least a fraction of α of total weight of the subtree.
Tree T:
αWT≤WT1≤(1-α)WT
αWT≤WT2≤(1-α)WT
T2
T1
Weight-Balanced Trees
Theorem
An α-weight-balanced tree of height h≥2 has at least
1 ℎ
( ) leaves.
1−α
Weight-Balanced Trees
Rebalance
2 1
n is current node α∈[ , 1 − ]
7 2
Case 1:
n->left->weight ≥ α*n->weight and
n->right->weight ≥ α*n->weight
No rebalancing
Weight-Balanced Trees
Case 2:
n->right->weight ≥ α*n->weight
If n->left->left->weight > (α+ε)n->weight,
do right rotation on node n
Else left rotation on n->left, followed right rotation on
node n.
2 1
ε≤ α -2α+
2
Weight-Balanced Trees
Case 3:
n->left->weight ≥ α*n->weight
If n->right->right->weight > (α+ε)n->weight,
do left rotation on node n
Else right rotation on n->right, followed left rotation
on node n.
Weight-Balanced Trees
Theorem
The weight-balanced tree structure supports search, insert,
and delete in O(logn) time.