The system uses only one stack to implement recursion, so you should be able
to do it too :-)

On 3/6/07, NUPUL <[EMAIL PROTECTED]> wrote:
>
>
>
>
> On Feb 28, 8:06 pm, "k3xji" <[EMAIL PROTECTED]> wrote:
>
> > Is there any way of calculating the depth of a binary tree without
> > using *recursive way*.Also not using *log2-1* method.I am asking this
> > because Is there any way of doing this kind of operation with just
> > using stacks or quenes.
>
> Yes. You can "simulate" recursion by explicitly creating your own
> stack and storing the pointers to the traversed nodes OR Create a
> threaded (inorder) binary tree, this too eliminates the need of
> recursion when traversing the tree in order.
>
> This solution is offered in a standard book on data structures by
> Tanenbaum.
>
> >In other words, is there a some kind of
> > compiler optimization just to avoid recursive call overhead?
>
> Not an optimization per se but the above avoids the recursion overhead
>
> >Here is
> > the recursive one (pseudo): Any comments?(Also optimization is not
> > important here.Is it just possible to implement an algorithm using one
> > stack or one quene,like traversal methods do?)
>
> Which "other" traversal methods are you talking about? The 'graph'
> traversal methods are usually specified recursively as they are easier
> to read/understand that way.
>
> Regards,
>
> Nupul
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to