While creating a tree from its inorder and preorder traversal.The output is not coming.Ples help’
Code link - https://ide.codingblocks.com/s/292393
Facing error while creating a tree from inorder and preorder traversal
@TusHar-AroRa-2294450460870717
Algorithm :
- Pick an element from Preorder. Increment a Preorder Index Variable (preIndex in below code) to pick next element in next recursive call.
- Create a new tree node tNode with the data as picked element.
- Find the picked element’s index in Inorder. Let the index be inIndex.
- Call buildTree for elements before inIndex and make the built tree as left subtree of tNode.
- Call buildTree for elements after inIndex and make the built tree as right subtree of tNode.
- return tNode.
https://ide.codingblocks.com/s/292624
dont forget to hit like and mark resolved if cleared
1 Like
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.