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 30. But in the graph suppose the weight of the left most edge (i.e. 4->6) is 40 then 4->6 is the longest distance not a->b. Let me know if I am making sense. On Sat, Jun 23, 2012 at 3:51 PM, Kumar Vishal <[email protected]> wrote: > 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 <[email protected]> wrote: > >> 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 <[email protected]> wrote: >> >>> 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 visit >>> https://groups.google.com/d/msg/algogeeks/-/jodahB_dChYJ. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Regards >> Kumar Vishal >> _________________________________________ >> *http://wethecommonpeople.wordpress.com/ * >> *h**ttp://kumartechnicalarticles.wordpress.com/<http://kumartechnicalarticles.wordpress.com/> >> * >> _________________________________________ >> >> >> > > > -- > Regards > Kumar Vishal > _________________________________________ > *http://wethecommonpeople.wordpress.com/ * > *h**ttp://kumartechnicalarticles.wordpress.com/<http://kumartechnicalarticles.wordpress.com/> > * > _________________________________________ > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards, avinash (+91) 9502681447 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
