one another solution using counting array...
void findwidth(BST* bt, int *arr, int count)//initially count is 0 for root
{
if(bt)
return;
arr[count]++;
count++;
if(bt->left)
findwidth(bt->left, arr, count);
if(bt->right)
findwidth(bt->right, arr, count);
return;
}
int maxwidth(BST* bt)
{
int count = 0, temp = 0, i = 0;
int arr = (int*) malloc(sizeof(int)*n); //here n is no of node
findwidth(bt, arr, count);
while(arr[i])
{
if(temp<arr[i])
temp = arr[i];
i++;
}
printf("width of binary tree is = %d", temp);
retrun temp;
}
On Mon, Jul 26, 2010 at 5:53 PM, umesh kewat <[email protected]> wrote:
> use levelorder traversal and calculate the number of node in same level by
> putting some condition :)
>
> On Mon, Jul 26, 2010 at 1:53 PM, vineel yalamarth <
> [email protected]> wrote:
>
>>
>>
>> No dude, they asked me to find width , in the sense ... find the maximum
>> number of nodes in any level.
>> And if you know how to find the diameter do post it....
>>
>>
>> --
>> 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]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Thanks & Regards
>
> Umesh kewat
>
>
>
--
Thanks & Regards
Umesh kewat
--
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.