you will have to take top-down/bottom-up approach.
getMaxWidth(node tree){
int n = getHeight(tree), w=1;
for(int i=1; i< n; i++){
w = getWidth(tree, i);
if(w <= maxWidth)
continue;
else
maxWidth = w;
}
Syso("Maximum width is"+maxWidth);
}
getWidth(node tree,level l){
if l == 1 return 1;
else if tree == null return 1;
else return getWidth(tree.getLeft(), level-1)+getWidth(tree.getRight,
level-1 );
}
I think this will get the job done.
On Sat, Jun 19, 2010 at 10:24 AM, harit agarwal <[email protected]>wrote:
> do a bfs traversal and insert a null marker after each traversal keep a
> variable max for maximum nodes at any level..
>
> O(n)
>
> --
> 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,
Chakravarthi.
--
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.