I'm learning data structures and found out that for binary search trees, there are two ways to 开发者_StackOverflow社区reconnect node when you delete item. Are those two ways (below) correct?
Link to the image to see it non-resizedYes, 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).
The two methods look correct. The first method does re-balance the tree while the second simply does the connect.
精彩评论