how the making tree with the use of inorder and preoreder traversal will be O(N)
it thimnk it should be O(N^2)
Construct from preorder
You are constructing each node only once(when you get to that node).So it cannot be O(n^2).
It will be O(n)
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.
making binary tree from preorder and postorder is O(N^2) its also similar to that so it will also of O(N^2)
Hey @deepakjumani09
You are right it works in O(n^2)
There is also an O(n) algo
You can see all this here https://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/
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.