I'm learning data structures and found out that for binary search trees, there are two ways to reconnect node when you delete item. Are those two ways (below) correct?
A:
The two methods look correct. The first method does re-balance the tree while the second simply does the connect.
Miky Dinescu
2010-10-16 18:02:50
I think that the re-balancing is coincidental in this case.
Vilx-
2010-10-16 18:04:01
thx, I will wait for few more answers before I accept answer
bossgameboy
2010-10-16 18:04:42
A:
Yes, they are. Note that you could also do the "mirror image" version of each way, so it's actually 4 ways in total.
In fact, there are quite few ways that would produce a valid binary tree. All you need to take care of is that the left child of a node is less than the node itself, and the right child is more. However the ways you have listed are the simplest ones that are typically used (unless it's a balanced tree and you need to rebalance it).
Vilx-
2010-10-16 18:03:22