Question: 2 A balanced binary - search tree The elegance of red - black trees and splay trees may sometimes leave us with a sense of
A balanced binarysearch tree
The elegance of redblack trees and splay trees may sometimes leave us with a sense of awe. How did they come up with such a nifty scheme to keep the binary search tree balanced? It is actually not that hard to balance a binary search tree. Many simple schemes can give us amortized running time. They may be lacking in elegance, but quite easy to understand.
Consider the following scheme. First, we store at every node the number of items in the subtree rooted This allows us to determine when the binary search tree becomes unbalanced. Let's define a node to be horribly unbalanced if the left subtree of has times the number of nodes than in its right subtree, or vice versa. All we will do in this scheme is to "fix up the subtree" if we detect that is horribly unbalanced.
Suppose that none of the nodes in a binary search tree with items is horribly unbalanced. Argue that the height of is Hint: use recursioninduction
Suppose that during an insertion, we detect that some node is horribly unbalanced. We can fix the subtree rooted at by taking apart the subtree and adding every item from this subtree into a balanced tree that is as balanced as possible. Describe how to accomplish this rebalancing in worst case actual time, where is the number of items in the subtree rooted at
Note: Do not use pseudocode to describe your algorithm. For example, if you want to sort some numbers in an array just say "Sort the values in
When you a insert a new key you may encounter several nodes that are horribly unbalanced nodes on the path from the root to where gets inserted. Where should you perform a rebalance first? at the horribly unbalanced node closest to the root? or closest to Justify your response.
Devise an amortized analysis for this data structure using the accounting method. Your analysis must show that the amortized running time of insert and search are
Note: You must state an invariant for your accounting scheme and argue that the invariant is maintained after each insert and search operation, including operations that perform rebalancing operations.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
