Algorithm of combining two binary trees?
问题 For example: two trees : 8 9 5 7 4 20 30 become one tree? 回答1: Without more details/constraints, the simplest solution is to take a leaf node of either tree, remove it, and use it as the root to the newly created three. In your example: 30 8 9 5 7 4 20 This works because your trees don’t appear to follow any particular order, don’t appear to be balanced, nor have any other constraints. Since any leaf node will do, this is an O ( n ) operation in the worst case (traverse one of the trees in