@Mohit : in ur code u are breaking out when there parent reaches root. But not every time will we have to reach root. For example: Leftmost right cousin of 1 is 9...in dat case parent should stop at 4. which is not the root. *Muthuraj R IV th Year , ISE PESIT , Bangalore*
On Wed, Aug 10, 2011 at 3:26 PM, muthu raj <[email protected]> wrote: > @coder dumca: If u apply DFS u will get a brother and not cousin. And yes > it works only for some cases. > > *Muthuraj R > IV th Year , ISE > PESIT , Bangalore* > > > > On Wed, Aug 10, 2011 at 2:24 PM, coder dumca <[email protected]>wrote: > >> apply BFS >> the node after the particular node(whode cousin to be find) will be the >> required node >> >> On Wed, Aug 10, 2011 at 2:15 PM, Puneet Chawla <[email protected] >> > wrote: >> >>> >>> Agree with mohit goel.. >>> >>> On Wed, Aug 10, 2011 at 11:22 AM, Mohit Goel >>> <[email protected]>wrote: >>> >>>> 10 >>>> 4 5 >>>> 2 7 6 11 >>>> 1 3 9 8 12 13 14 15 >>>> >>>> >>>> i think we should first find the parent of the particular node ..then >>>> apply the concept as told by Brijesh on it .... >>>> >>>> p =parent(q); >>>> r = parent(p); >>>> count =1; >>>> while(p ==isright(r)) >>>> { >>>> p=r; >>>> r=parent(r); >>>> count++; >>>> if(r==root) >>>> break; >>>> >>>> } >>>> >>>> if(d =right(r)) >>>> { >>>> while(count!=0) >>>> { >>>> if(d->left) >>>> d=d->left; >>>> else d=d->right; >>>> count--; >>>> } >>>> } >>>> else return NULL; >>>> o/p=d->value; >>>> >>>> >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> With regards >>> ............ >>> Puneet Chawla >>> Computer Engineering Student >>> NIT Kurukshetra >>> >>> -- >>> 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. >>> >> >> -- >> 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. >> > > -- 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.
