How we Come to know that the input one tree get over and input for another tree get started.
Input Format Not Cleared
Hello @vikram.keswani108
The input of the tree is given in pre-order format.
So first the root node will be provided, then the left subtree and then the right subtree.
A true value would indicate that either the left or the right subtree exists
A false value would indicate that either there is No left subtree or No Right subtree.
When you have explored the left and right of all the nodes, you know the tree is over.
Example:-
10 true 20 true 30 false false false true 40 false false
10 is the root node.
true indicates that there is a left subtree of 10 and 20 is the value of the left child.
Now we will first explore 20 and come back to right subtree of 10 later as we are taking input in preorder format
true indicates that there is a left subtree of 20 and 30 is the value of the left child.
Now we will first explore 30 and come back to right subtree of 20 later
false indicates that there is no left subtree of 30
false indicates that there is no right subtree of 30
30 is EXPLORED
Now 30 is over we will move back to 20
false indicates that there is no right subtree of 20
20 is EXPLORED
Now 20 is over we will move back to 10.
true indicates that there is a right subtree of 10 and 40 is the value of the right child
10 is EXPLORED
Now we will explore 40
false indicates that there is no left subtree of 40
false indicates that there is no right subtree of 40
40 is EXPLORED
So we have explored all the nodes and their children, the tree is complete, and now the second tree will start.