patternMinor
Worst Case for AVL Tree Balancing after Deletion
Viewed 0 times
caseafteravlforbalancingdeletionworsttree
Problem
After deleting a node in an AVL tree, self-balancing (zig-zag rotation or the left-right balancing) maintains O(logn) time that is not guaranteed in other unbalanced trees (like BST).
The Balancing operation is said to be O(logn).
What is the worst case for balancing? (I guess it will require balancing at every node all the way up till the root)
Any specific type of tree providing the worst case?
The Balancing operation is said to be O(logn).
What is the worst case for balancing? (I guess it will require balancing at every node all the way up till the root)
Any specific type of tree providing the worst case?
Solution
To make a lot of rebalancing, you would like to make your AVL tree as imbalanced as possible. And the worst case is a Fibonnachi-like tree:
, where $T_n$ is a tree with $T_{n-1}$ as a left child and $T_{n-2}$ as a right child ($T_1=T_2=$single-node tree).
On this example, if you remove
, where $T_n$ is a tree with $T_{n-1}$ as a left child and $T_{n-2}$ as a right child ($T_1=T_2=$single-node tree).
On this example, if you remove
19, then node 18 must be rebalanced. After that, node 13 must be rebalanced. Essentially, you will have a rebalance at every level above node 20. You can build an arbitrary large such tree. I didn't check, but it should be simple to prove that removing the rightmost node always suffices for the worst case.Context
StackExchange Computer Science Q#128245, answer score: 4
Revisions (0)
No revisions yet.