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 = height(&q1,tree->left,0);
   q1.h2 = height(&q1,tree->right,1);


   q3 = max_dist(tree->left);
   q4 = max_dist(tree->right);  *
*  *
*   if((q3.h1+q3.h2)>(q4.h1+q4.h2))
   {
         if((q3.h1+q3.h2)>(q1.h1+q1.h2+1))
                  return q3;
        else
                 return q1;
    }
   else
   {
        if((q4.h1+q4.h2)>(q1.h1+q1.h2+1))
                return q4;
        else
               return q1;
  }*
*}   *
**
**
*int height(queue *Q,struct node* node,int i)
{
      if(node == NULL)
        return;

     if(node>left == NULL && node->right == NULL)
    {
           Q->(q[i]) = node;
           return 0;
     }

      return 1 +  max(height(Q,node->left,i), height(Q,node->right,i));
}*

On Mon, May 30, 2011 at 2:35 PM, anshu mishra <[email protected]>wrote:

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



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=100000655377926 *

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