Re: [algogeeks] Build BST from binary tree without extra space

2010-04-30 Thread Rajesh Patidar
thing is that u r using recursion and we don't have to use it( recussion use memory indirectly) as per the question On Thu, Apr 29, 2010 at 3:55 PM, Algoose Chase wrote: > If you mean to convert the binary tree to binary search tree directly , then > > BinarytoBST(Node* root) > { >    if( root =

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-29 Thread Rajesh Patidar
@ashish i forgot recussion uses memory but if we have to do it without using stack also then pickup the root and add it to the bst and to fill the vacant position of root choose left node and make it root and to adjust previous right node at it to leaf eg : D /

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-29 Thread Algoose Chase
If you mean to convert the binary tree to binary search tree directly , then BinarytoBST(Node* root) { if( root == nulll) return; BinarytoBST(root->left); BinarytoBST(root->right); if( root->left ) Node* NodeL = MAX(root->left); if ( root->right ) Node* NodeR = MIN(root->ri

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-29 Thread Rajesh Patidar
ya post order traversal will not have these problem theme time i haven't thought the problem with pre and inorder. On Wed, Apr 28, 2010 at 10:16 PM, Vivek S wrote: > @Rajesh Patidar > I think we should do in Post order traversal alone. If we go by > Preorder/Inorder we might lose track of childre

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-29 Thread Algoose Chase
Hi, How do you define "without extra space" ? Doing any order traversal either using recursion or using iteration is going to take extra space . If you are given a binary tree represented by pointers that points to children nodes is it possible to do a heap sort without an array ? On Thu, Apr 29

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread sharad kumar
my choice is build a min heap .sort the array with heap sort.then find the median of the sorted array and build tree On Wed, Apr 28, 2010 at 10:16 PM, Vivek S wrote: > @Rajesh Patidar > > I think we should do in Post order traversal alone. If we go by > Preorder/Inorder we might lose track

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread Vivek S
@Rajesh Patidar I think we should do in Post order traversal alone. If we go by Preorder/Inorder we might lose track of children node that is currently being inserted into the BST. - correct me if im wrong :) On 28 April 2010 15:30, Rajesh Patidar wrote: > pickup node in any order no matter(pre

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread Ashish Mishra
@rajesh can u explain your soln how u r doing inorder, pre or whatever (without using stack) and at same time build BST On Wed, Apr 28, 2010 at 3:30 PM, Rajesh Patidar wrote: > pickup node in any order no matter(pre,post,inorder) and just one by > one. start adding the node into bst no need to u

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread Prasoon Mishra
@ Rajesh: there may be a problem with this solution. Suppose I start detaching the nodes from the binary tree in the following order - > Root, Left, Right. So as soon as i detach the root of the binary tree and form a new BST with it ( on which i m going to make further node additions), I am left w

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread Rajesh Patidar
pickup node in any order no matter(pre,post,inorder) and just one by one. start adding the node into bst no need to use extra space u have to just ditach the node from binary tree and attach it in bst. On Wed, Apr 28, 2010 at 1:18 AM, Ashish Mishra wrote: > How to build BST from binary tree in p

Re: [algogeeks] Build BST from binary tree without extra space

2010-04-28 Thread Nikhil Agarwal
On Wed, Apr 28, 2010 at 1:18 AM, Ashish Mishra wrote: > How to build BST from binary tree in place i.e without extra space ?? > Are you looking for: http://discuss.joelonsoftware.com/default.asp?interview.11.781167.4 > -- > You received this message because you are subscribed to the Google Gr