"Coding is just like talking to a unknown girl. Once you talked to her with guts, the next time you'll never afraid",Really? Yes , try it Now !!!
Everything here is for education and learning purpose only , individual holds rights on outer posts/links etc.
Team Cracking The Code
About Me
▼
Monday, October 31, 2011
Given a node of a BST, modify it in such a way that the given node becomes the root. The tree should still be BST.
Assuming that every node has parent pointer, we can perform left or right rotation(depending on whether the node is right or left child)until we reach the root.
Assuming that every node has parent pointer, we can perform left or right rotation(depending on whether the node is right or left child)until we reach the root.
ReplyDeleteIs this correct?
Perform an inorder traversal and find the given node in it and keep the given node as root and insert the nodes to it in the given inorder traversal.
ReplyDeleteThis will take O(N log N)
I believe there will be a better solution similar to AVL Tree rotation