On an Avl tree, when you delete a node with 2 children.. I know that you can replace it either with its successor (min value on right subtree) or its predecessor (max value on left subtree).
My question is that: In standards, to what sub tree do I swap with the node?
The successor or the predecessor?
Thanks! 🙂
So long as you do all the necessary rebalancing afterwards, you can use either one — the algorithm works out either way.
If you wanted to be really clever, you could pick either one based on which one would require the least rebalancing afterwards. That’d be considerably more complicated than just always picking the next larger or next smaller key, though.