@piyush well i missed the line" find two nodes line" so just coded
finding the diameter of tree..& so why in hurray i posted the solution
but i found its slightly changed from diameter of BT..anyways let me
give approach to solve this problem

find the height of left & right sub tree fro each node & take two
variables of current & maxheight ..one things is sure that maximum
distance always exist in two leave node of BT So we will also take two
node variable node1 & node2 so 1st we check currentheight(sum of left
& right sub tree height for every node) is greater then maximumheight
& then update maximumheight=currentheight & then we will do like
while( node.left!=null)  if node.right==null so in this case root will
be other node
else if node->left=null then we got to right side otherwise finally we
will got to both side to update the both nodes so this way we can get
the two nodes with maximum distance *& these two nodes will always be
the leaf nodes.( it can happened that we can have the both nodes in
any of these subtree aswell)
as far as Time Complexity Concerned its no more less then (O(N^2)
in summary basically we have to find two nodes which having maximum
depth .its just thought , comments are welcome..Some of you might
stuck with approach

Working on The Algo & if won't fail then will post code asap.


Thanks
Shashank

-- 
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.

Reply via email to