Re: [algogeeks] Re: Given a node of BST make it the root

2011-11-01 Thread kumar raja
@Dave : Wonderful answer sir.. On 31 October 2011 12:50, Dave dave_and_da...@juno.com wrote: @Ankuj: Your method would be O(n), where n is the number of nodes in the tree. However, it can be done with a sequence of tree rotations. If the desired node is not the root of the tree, rotate it

[algogeeks] Re: Given a node of BST make it the root

2011-11-01 Thread Navneet
It's called as Splaying, accessing any node results in that node becoming the root. The main idea is that some node which is currently being accessed might get accessed again or sometime near in future. Hence, for better search times, splaying is a good idea. (AVL tree rotations will help you

[algogeeks] Re: Given a node of BST make it the root

2011-10-31 Thread Dave
@Ankuj: Your method would be O(n), where n is the number of nodes in the tree. However, it can be done with a sequence of tree rotations. If the desired node is not the root of the tree, rotate it with its parent. This preserves the BST property and makes the desired node one level closer to the