[algogeeks] Re: Binary Tree problem - careercup book que4.8

2011-11-26 Thread bugaboo
Hey Swathi, The problem does mention any path but refers to straight paths along a root to leaf path. Therefore, a path need not necessarily start from the root or end with a leaf but should be along the path from the root to a leaf. On Nov 25, 4:05 am, Swathi chukka.swa...@gmail.com wrote:

Re: [algogeeks] Re: Binary Tree Problem

2011-06-05 Thread Amit Jaspal
@ piyush: u dont need to work with queues, just modify the height function... int findDiameter(node *root,int *p){ printf(hi\n); //if(root-left==NULL root-right==NULL) return 0; if(root!=NULL){ int l,r; l=findDiameter(root-left,p);

Re: [algogeeks] Re: Binary Tree Problem

2011-06-05 Thread Piyush Sinha
@amit jaspal..I am not able to understand how will u be saving the nodes for which the largest diameter existsI know how to find the largest diameter but the question was to find the nodes too for which the largest diameter exists...please correct me if I missed something On 5/30/11, Amit

Re: [algogeeks] Re: Binary Tree Problem

2011-05-31 Thread Piyush Sinha
Dudethe question was to find the two nodes also for which the maximum distance exists.in ur code there is nothing as suchkindly read the question carefully before posting... On 5/31/11, bittu shashank7andr...@gmail.com wrote: HI All Yes It The Diameter of BT . Can be done in O(N)

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread ross
@piyush, Hi, thanks alot for the solution, Thats to find the diameter of a tree. :) But, how would you obtain the 2 nodes which have the max. distance betwn them? On May 30, 1:17 pm, Vipul Kumar vipul.k.r...@gmail.com wrote: That is same as finding the diameter of the tree. On Mon, May

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Maksym Melnychok
simplest algo: find a node with max depth M and go up tree calculating max depth of all upper branches that do not contain M until reaching root node -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Piyush Sinha
@ross...I think it can be done by taking a queue/stack...I am working on the code...Please comment if there is any error in my approach.. On Mon, May 30, 2011 at 2:19 PM, Maksym Melnychok keym...@gmail.com wrote: simplest algo: find a node with max depth M and go up tree calculating max depth

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread anshu mishra
this is a very standard problem :D start with any node(x) find the node which is at maximum distance. now start with x travese the tree and find the node(y) which is at maximum distance. so finally answer wil be (x, y) traversing the tree two times. so the order for finiding the such nodes

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread anshu mishra
little modification start with any node(r) find the node(x) which is at maximum distance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Piyush Sinha
I think following algo will work..I haven't tested it plus its in its crude form...Kindly correct me if i am wrong.. *typedef struct queue { struct node *q[2]; int h1,h2; }queue;* ** *queue max_dist(struct node * tree) { if (tree == NULL) return; queue q1,q2,q3; q1.h1 =

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
won't this simple algo work ?? start from root node, say it has value 0 at any time if a node has a value v pass v-1 to left subtree and v+1 to right subtree keep track of max and min final answer will be max -min = Diameter of tree. correct me if i m wrong. -- You received this message

Re: [algogeeks] Re: Binary Tree Problem

2011-05-30 Thread sunny agrawal
nope, it will not work :( got a case On Mon, May 30, 2011 at 11:57 PM, sunny agrawal sunny816.i...@gmail.comwrote: won't this simple algo work ?? start from root node, say it has value 0 at any time if a node has a value v pass v-1 to left subtree and v+1 to right subtree keep track of max

[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread T3rminal
Right!! that is pretty standard problem but the solution u have given is for undirected graphs and intuitively binary trees are directed. Piyush solution will work for binary tree. On May 30, 2:04 am, anshu mishra anshumishra6...@gmail.com wrote: this is a very standard problem :D start with