what is overall timexomplexity for build tree we also doing searching for element
Overall time time complexity
hello @Vikaspal
you are traversing the whole preorder
array inside the recursion and in each stack frame you are searching a number in inorder
traversal array. So O(N*N) = o(N^2)
.
mathematically we can represent worst case recurrence as.
T(n)= T(n-1) + O(n)
on solving this we get O(n^2)
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.