Yeah, you can do it either way. You can even add a dummy element
instead of checking for empty and popping each time.
But basically yeah, that's how I'd do it.

Manjunath put it in a nice concise way.

On Jul 29, 3:42 am, Sathaiah Dontula <[email protected]> wrote:
> @Minotauraus
>
> I feel Queue gives more picture.
>
> Thanks,
> Sathaiah Dontula
>
>
>
> On Thu, Jul 29, 2010 at 3:53 AM, Minotauraus <[email protected]> wrote:
> > Width of a Tree = maximum number of nodes at the same level.
> > Example:
> >                            a
> >                       b        c
> >                     d  e      f  g
> >                        h      i j
>
> > Here, the max. width is 4 at level 3->d, e, f, g
>
> > Algo to find width:
>
> > 1. Push node on stack1
> > 2. Pop node from stack1 if not empty
> > 3. visit node and push children on stack2
> > 4. goto 2 if stack1 not empty
> > 5. if stack1 empty, number of elements in stack 2>width  then width=
> > number of elements on stack2
> > 6. repeat steps 2-5 for stack2
>
> > basically keep pushing children on stack until 1 stack is not empty,
> > the value when it is empty will give the width at that level.
> > Use one variable to store this width by checking if current width is
> > greater.
>
> > -Minotauraus.
> > On Jul 26, 5:23 am, 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%2bunsubscr...@googlegroups­.com>
> > <algogeeks%2bunsubscr...@googlegroups­.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > --
> > > Thanks & Regards
>
> > > Umesh kewat- Hide quoted text -
>
> > > - Show quoted text -
>
> > --
> > 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%2bunsubscr...@googlegroups­.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
>
> - Show quoted text -

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