Consider this binary search tree:
14 / \ 2 16 / \ 1 5 / 4
Suppose we remove the node with value 2. What will be the new tree?
14 / \ 4 16 / \ 1 5 |
||
14 / \ 5 16 / \ 1 4 |
||
4 / \ 5 16 / / 1 14 |
||
14 / \ Null 16 / \ 1 5 / 4 |
Given binary search tree
14 / \ 2 16 / \ 1 5 / 4
If we remove node 2, we can update the tree in 2 ways.
way - 1: Replace 2 with the maximum value of left sub tree
way -2 : Replace 2 with the minimum value of right sub tree.
Accroding to way -2, option 1 is correct
14 / \ 4 16 / \ 1 5
2nd option is wrong. It is not satisfying binary search tree property.
3rd, 4th options are wrong because they have not forming trees based on the method mentioned above.
Get Answers For Free
Most questions answered within 1 hours.