[algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Avinash
Some how I found that we need to run bfs twice to get the largest distance between any two nodes of a tree. Please explain me how it works. regards, avinash -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Navin Kumar
Is this similar to finding the diameter of a tree(longest disteance between two leaves) ?? If yes than visit this link http://www.cs.duke.edu/courses/spring00/cps100/assign/trees/diameter.html On Sat, Jun 23, 2012 at 2:44 PM, Avinash jain.av...@gmail.com wrote: Some how I found that we need to

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Navin Kumar
Is longest path between two node in a tree is equal two logest path between two leaves?? On Sat, Jun 23, 2012 at 5:35 PM, Navin Kumar algorithm.i...@gmail.comwrote: Is this similar to finding the diameter of a tree(longest disteance between two leaves) ?? If yes than visit this link

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Avinash Jain
no this problem is different from finding the longest path which is actually maximum number of nodes covered in the longest path On Sat, Jun 23, 2012 at 5:45 PM, Navin Kumar algorithm.i...@gmail.comwrote: Is longest path between two node in a tree is equal two logest path between two leaves??

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Kumar Vishal
What I can think is case is : 10 / \ 6 13 / \ 4 5 / \ \ 6 7 8 / \ \ 9 a b so from a-b is a-7-4-2-5-8-b 1- Left Tree then 2- Right Tree add them On Sat, Jun 23, 2012 at 3:49 PM, Kumar Vishal kumar...@gmail.com wrote: What I can think

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Kumar Vishal
What I can think is case is : 1 / \ 2 3 / \ 4 5 / \ \ 6 7 8 / \ \ 9 a b so from a-b is a-7-4-2-5-8-b On Sat, Jun 23, 2012 at 2:44 PM, Avinash jain.av...@gmail.com wrote: Some how I found that we need to run bfs twice to get the largest distance

Re: [algogeeks] Re: Largest Path in Tree [SPOJ BENFECT]

2012-06-23 Thread Avinash Jain
you are just finding the diameter of the tree. Remember the graph I am talking about is weighted. So if two adjacent vertices has infinite weight than that would be the longest distance between any two vertices in the graph. e.g. In you diagram suppose the sum of weight of the edges from a-b is