how is the tree is building up in the given type of input
Structurally identical tree
Refer this:
sir i dont want code but i want to know how tree has to be constructed can you take simple test case and give its output preorder so that i can understand the flow of construction
Dry run the above with the sample case
You just have to take the input in preorder format
Say 10 true 20 true 40 false false true 50 false false true 30
It means 10 is the root node.
next input is true…so it means a left child is present and its value is 20.
now again after 20, there is a true…which means left child of 20 is present and it is 40.
Now after 40 comes false…which means there is no left child…
Again there is a false…so there is no right child…So you can say now that 40 is a leaf node.
Now…there is a true(you have returned back to node 20)…so right child of 20 is present and its value is 50.
Now comes false twice…which means there is no left child and right child of node 50…
So…in this order you have to proceed and build the tree.
Oh great thanks bhaiya i understood now…
In this question it is always necessary that first element is present it might be possible that input will be false??
Yes you can assume that root node is NULL by default.
If nothing is given as input it will mean NULL.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.