One queue certainly suffices. Sometimes two are very nice. E.g. if you
have the task of printing all nodes at level N and you don't have
level numbers in the nodes. With two queues, all the nodes in a queue
at a given time are on the same level, so this problem is elegantly
solved. WIth one it's possible but messier. You have to track the last
node added at each level or something equally messy and error prone.

By the same logic, you can do the zig-zag order with a single deque,
but it's also messier this way.

On Dec 11, 12:23 pm, atul anand <atul.87fri...@gmail.com> wrote:
> @Gene : if i am not wrong , level order traversal can be done using only 1
> queue....why 2 queue???
>
>
>
> On Sun, Dec 11, 2011 at 9:53 PM, AMAN AGARWAL <mnnit.a...@gmail.com> wrote:
> > Hi,
>
> > Suppose we have a binary search tree as 15,12,18,17,21,11,14
> > then O/P will be 15 12 18 21 17 14 11.
> > so the successor of 15 is 12 the successor of 12 is 18 and so on.
>
> > I hope now its clear.
>
> > Regards,
> > Aman.
>
> > On Sun, Dec 11, 2011 at 6:26 PM, WgpShashank 
> > <shashank7andr...@gmail.com>wrote:
>
> >> @atul zig-zag mean spiral traversal of tree e.g. alternate the level
> >> while traversing , if previous traversal is left to right , then next level
> >> will be right to left .
>
> >> @aman .quest has little ambiguity its says successor but ebvery nodes can
> >> have we can ore-order , inorder ,postorder successor isn't it  ?? but i am
> >> assuming u r interesting in pre-order succesor so then 1st find the
> >> per-order successor of each node & then set it , finally traverse it ?
>
> >> correct me if i am wrong ?
>
> >> Thanks
> >> Shashank Mani
> >> Computer Science
> >> BIT Mesra
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Algorithm Geeks" group.
> >> To view this discussion on the web visit
> >>https://groups.google.com/d/msg/algogeeks/-/b51VObaoMZIJ.
>
> >> 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.
>
> > --
> > AMAN AGARWAL
> > "Success is not final, Failure is not fatal: It is the courage to continue
> > that counts!"
>
> > --
> > 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.

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