Wap to delete an user input node of a binary tree if it is a leaf node | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Wap to delete an user input node of a binary tree if it is a leaf node

input : A binary tree. And a number. output : if possible print number otherwise "not possible".

10th Oct 2017, 10:38 AM
Anirban Bal
Anirban Bal - avatar
6 Answers
+ 1
The title and the description is ambigious. Would you please clarify?
14th Oct 2017, 2:05 PM
Norbivar
Norbivar - avatar
+ 1
Suppose you have a binary tree and you want to delete a node(containing the data which is user-input) from it. Condition, if it is the leaf node, delete it else print "not possible" and if the data not present in the tree print "data not exist".
14th Oct 2017, 2:24 PM
Anirban Bal
Anirban Bal - avatar
+ 1
Is the tree ordered? (in a different form: is it a binary search tree)
14th Oct 2017, 3:12 PM
Norbivar
Norbivar - avatar
+ 1
If it is ordered, then simply search for the value and if the value has no children, delete (and print number). If it has any, don't delete (and print "not possible") it is the same for an unordered, ordinary binary tree. The only difference would be in the searching algorithm.
14th Oct 2017, 3:16 PM
Norbivar
Norbivar - avatar
0
it's a binary tree.
14th Oct 2017, 3:15 PM
Anirban Bal
Anirban Bal - avatar
0
Thanks
14th Oct 2017, 3:34 PM
Anirban Bal
Anirban Bal - avatar