Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

by jryan (Vicar)
on Jun 16, 2008 at 21:56 UTC ( #692389=note: print w/ replies, xml ) Need Help??


in reply to Re: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
in thread Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

Thats definitely the root of my problem. I think your approach to an iterator might help though, I think I just need to figure-out how to integrate it with my code. One question before I try it out: what is more efficient memory-wise about your second approach than your first approach?


Comment on Re^2: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
Re^3: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
by Limbic~Region (Chancellor) on Jun 17, 2008 at 13:46 UTC
    jryan,
    Again, I am at the conference so I don't have the time to give you a proper response. The second one, which is more memory efficient, only requires as many nodes on the stack as the max depth of the tree. It does this by creating an iterator (one item) for the stack instead of a list of nodes (many) to visit. You then work through that iterator before moving on. This is a poor explanation - I know, but I won't be available to explain in detail until Thursday.

    Cheers - L~R

      In case you're curious,

      only requires as many nodes on the stack as the max depth of the tree.

      So does mine below.

      It does this by creating an iterator (one item) for the stack instead of a list of nodes (many) to visit.

      Mine doesn't wrap the array index in an iterator. I started making a version that did, but it was complicating the ability to return the path that led to the node (like the OP's) instead of just the node (like yours).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://692389]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2014-11-26 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls