Rebalancing an arbitrary BST?
You might want to look into the Day-Stout-Warren algorithm, which is an O(n)-time, O(1)-space algorithm for reshaping an arbitrary binary search tree into a complete binary tree. Intuitively, the algorithm works as follows: Using tree rotations, convert the tree into a degenerate linked list. By applying selective rotations to the linked list, convert the list … Read more