I was wondering if someone could provide some helpful insight on deleting nodes from a 2d binary search tree.
I understand there's four cases, the first of which I've completed:
- Deleting a node with no children (a leaf), simple, just set the pointer to that node to null.
- Deleting a node with one child on the left node and the right node is null.
- Deleting a node with one child on the right node and the left node is null.
- Deleting a node with two children, left and right.
I am not sure how to exactly do 2,3, and 4. I've tried to do it iteratively, however, that doesn't seem to be working. I'm assuming this must be done recursively. Can someone please shed some light on how this would be done exactly. This is in java, shouldn't matter though :)