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
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
@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,
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;
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;
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,
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
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
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 =