Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by Limbic~Region (Chancellor)
on Jun 16, 2008 at 21:21 UTC ( [id://692373]=note: print w/replies, xml ) Need Help??


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

jryan,
I am at YAPC::NA 2008 and admittedly have only skim read your code. I have a couple of depth first search (DFS) iterators at:

It doesn't matter if you are letting perl manage the call stack (recursive function) or you are managing your own queue/stack (@work) - you will run into memory problems if you have to put more items on the stack then you take off. If this is the root of your problem (and I haven't read far enough to know for sure), then you will need to take a different approach.

Cheers - L~R

  • Comment on Re: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

Replies are listed 'Best First'.
Re^2: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
by jryan (Vicar) on Jun 16, 2008 at 21:56 UTC
    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?
      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://692373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-23 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found