Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-22 Thread anshu mishra
first try to understand the sol then comment. it is for binary tree not for BST. On Mon, Nov 21, 2011 at 10:25 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: For BST it would be rather simpler. find the first node which lies in between the two. On Wed, Nov 16, 2011 at 1:44 PM, anshu

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-22 Thread abhishek kumar
If you maintain the parent, it'll be a simple problem. Just go to the two nodes and then trace their parents till you reach the common node. On Tue, Nov 22, 2011 at 1:59 PM, anshu mishra anshumishra6...@gmail.comwrote: first try to understand the sol then comment. it is for binary tree not for

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-22 Thread Piyush Grover
@anshu I was just replying to the earlier comments not to ur post. On Tue, Nov 22, 2011 at 2:23 PM, abhishek kumar abhi5...@gmail.com wrote: If you maintain the parent, it'll be a simple problem. Just go to the two nodes and then trace their parents till you reach the common node. On Tue,

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-21 Thread Piyush Grover
For BST it would be rather simpler. find the first node which lies in between the two. On Wed, Nov 16, 2011 at 1:44 PM, anshu mishra anshumishra6...@gmail.comwrote: Node *LCA(node *root, node *e1, node *e2, int x) { Node *temp =NULL; Int y = 0;

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-16 Thread anshu mishra
Node *LCA(node *root, node *e1, node *e2, int x) { Node *temp =NULL; Int y = 0; If (root-left) temp = LCA(root-left, e1, e2, y); x+=y; if (temp) return temp; if (x==2) return node;

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-14 Thread AMAN AGARWAL
Hi, I think it matters whether its a bst or normal tree. In BST left node is smaller and the right node is greater than the root node, but no such constraint is applicable for a binary tree. Regards, Aman. On Mon, Nov 14, 2011 at 10:12 AM, sumit mahamuni sumit143smail...@gmail.com wrote: Hi,

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-14 Thread sumit mahamuni
Yeah, right. the same algo of binary tree can be used for bst also but using that is expensive. On Mon, Nov 14, 2011 at 9:56 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote: Hi, I think it matters whether its a bst or normal tree. In BST left node is smaller and the right node is greater than

[algogeeks] LCA of a Binary tree not a binary search tree

2011-11-13 Thread AMAN AGARWAL
Hi, Please tell me the solution of this question. write a program which find LCA of a binary tree. It is not a BST Regards, Aman, -- AMAN AGARWAL Success is not final, Failure is not fatal: It is the courage to continue that counts! -- You received this message because you are subscribed to

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-13 Thread aritra kundu
struct node{ int data; struct node* left; struct node* right; }; struct node* lca(struct node* root,struct node* a,struct node* b){ if(!root) return NULL; if( root==a || root ==b) return root; struct node* left = lca(root-left,a,b); struct node* right =