I donot understand the output format,ie,how tree root is 4?
I donot understand that how every node is returning to its root and finally to main root each timeā¦plz explain me that logic and tell me that line of code which is doing this
Hey Anshul, for balanced BST we must take root as centre element so that we have equal numbers on left and right part, this follows recursively as:
1 2 3 4 5 6 7
so 4 is current root and you call your left subtree for {1,2,3} and right subtree for {5,6,7}
now on left part 2 is current root and you further call on left for {1} and on right for {3},
Try implementing this or you may go for editorial.
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.