views:

19

answers:

2

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?

alt text Link to the image to see it non-resized

A: 

The two methods look correct. The first method does re-balance the tree while the second simply does the connect.

Miky Dinescu
I think that the re-balancing is coincidental in this case.
Vilx-
thx, I will wait for few more answers before I accept answer
bossgameboy
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-