Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
- Remove as in standard BST.
- Keep track of LastNodeCount and NodeCount with class variables.
- LastNodeCount is the node count of the tree when the last rebuilding operation occurred.
- If NodeCount <= a * LastNodeCount, rebuild must occur.
- We rebuild the entire tree from the root.
- The scapegoat is any ancestor of the inserted node that is not a-weight-balanced.
- We choose the scapegoat closest to the inserted node.
- Recurse from inserted node to root.
- Check a-balance at each node.
- Return first node unbalanced node
If begin != end
{
mid = (begin + end)/2
cRoot = array[mid]
rebuild(cRoot->left , begin, mid)
rebuild(cRoot->right, mid + 1, end)
}
- No rotations like AVL tree
- Traverse tree in-order, storing nodes in array.
- Root for balanced tree will be at median (begin + end)/2.
- Recursively build tree from array.
- Insert node into tree as with standard BST.
- Keep track of depth of node to be inserted.
- Check weight balance
- a-weight-balance implies a-height-balance
- tree height <= log1/a(# of nodes in tree)
- If depth violates height balance, find scapegoat and rebuild tree rooted at scapegoat.
Advantages:
Disadvantages:
- Self-balancing binary search tree
- alpha-weight-balanced
- balance depends on ratio called alpha, a.
- 0.5 <= a < 1
- Tree is balanced when:
# nodes in child subtree <= a * # nodes in parent tree
- Once balance is exceeded, we find a scapegoat.
- Subtree where balance is violated.
- Rebuild tree rooted at scapegoat.