@amit jaspal..I am not able to understand how will u be saving the
nodes for which the largest diameter exists....I 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 Jaspal <amitjaspal...@gmail.com> wrote:
> @ 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);
>             r=findDiameter(root->right,p);
>             *p=max(*p,(l+r));
>             return max(l,r)+1;
>     }
>     return 0;
> }
>
>
>
> On Mon, May 30, 2011 at 3:16 PM, Piyush Sinha
> <ecstasy.piy...@gmail.com>wrote:
>
>> 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
>> <anshumishra6...@gmail.com>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 algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> 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 algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Amit Jaspal.
>
> Men do less than they ought,
> unless they do all they can
>
> --
> 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 email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to