can you please give me a hint to build a tree with preorder traversal using true and false…
Preorder built of tree
The first element entered is the head, after that if it says true means its left child exist and then its value is there, then as in pre-order we will have left child of child, if it exist it will be true and process will repeat else we will move to right child of parent (if right child we will have true followed by value)
x false false (leaf node)
x false true 2 false false (x has right child which is leaf)
x true 3 false false false (x has left child 3, 3 is leaf)
is it possible to implement it with recursion or i have to use stach here???
Every problem that can be implemented with recursion can be implemented with stack(might be difficult but can be done with stack or stack and queue combination). Recursion seems to be easier approach here.
can you please help me to find that one wrong test case, other three are okay…
You are comparing the data also. You just have to check if it is structurally identical.
So consider test case:
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
10 true 21 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
Output must be true.
@nikhilmeena you need to only check the structure, value in nodes can be different.
If this solves your doubt mark it as resolved.
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.