Professional Documents
Culture Documents
4B Trees2
4B Trees2
Trees
Part 2
Balancing a tree:
1.Copy all tree nodes to an
array
2.Sort the array
3.Clear the tree
4.Call balance() method to
rebuild the tree
Right rotation
Left rotation
PARENT (i)
return floor((i-1)/2)
The root of the tree A[0] and LEFT (i)
given index i of a node, the return 2i+1
indices of its parent, left child and RIGHT (i)
return 2(i + 1)
right child can be computed: