For solution to this problem see http://groups.google.co.in/group/algogeeks/browse_thread/thread/adc95dcf96020a7/2943fd3c5a116fee?hl=en&lnk=gst&q=binary+tree+to+binary+serach+tree#
In that thread, I have a doubt regarding solution posted by @"Algoose Chase". The code posted is good as I feel except for the condition if( NodeL->Data > root->data) { .... } if( NodeR->Data <= root->data) { .... } Here If you find that the present node's (say 'n1') value if less than the MAX (say 'n2' ) of so far constructed BST in the left tree, then if is for sure that that MAX ('n2') of the left tree will replace the present node 'n1'. This will make sure that all nodes to the left are less than the new root 'n2', but we are not sure that the remaining nodes n the left tree are all less than 'n1'. So in "if( NodeL->Data > root->data)" condition, "temp = root-data; root->data = NodeL->data" is correct but instead of doing Nodel->data = root->data; BinarytoBST(NodeL) we should simply say deleteNode(tree->left,NodeL);//This will delete NodeL from a BST rooted at tree->left, taking into account delete conditions for deleting right most child of BST //(because NodeL was the right most child) InsertNode(tree->left,temp); Do share your views. Thanks, Sourav On Sep 27, 7:58 am, prodigy <1abhishekshu...@gmail.com> wrote: > 15 > / \ > 8 25 > / \ > 20 22 > > On Sep 26, 10:45 am, Chonku <cho...@gmail.com> wrote: > > > This can also be done if we do an inorder traversal of the binary tree and > > look for the longest continuous sequence of numbers in ascending order. > > Your idea will fail for above case. > > In Order => 8 15 20 25 22 > longest continuous sequence of numbers in ascending order => 8 15 20 > 25 > > But that's not the answer (I hope you realize what correct output > would be ) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.