in reply to Re^10: Finding All Paths From a Graph From a Given Source and End Node
in thread Finding All Paths From a Graph From a Given Source and End Node
UPDATE: I expected this part { %$seen } to be quite expensive .... does it even make sense?
Well, it does no harm :)
Um. Do you mean:
It just makes a copy (anonymous reference) of the seen hash(ref).
I make a copy because I want any changes made to it at deeper levels of recursion, to be unwound as the recursion unwinds.
It's purpose is obviously to prevent the algorithm from going in circles when it re-encounters a node it has already visited. But when we visit a node a deeper level we don't to permanently prevent it from visiting that node again if it reaches it via different path earlier in the recursion but later in the iteration.
Hm. Not sure that description works?
Essentially, the hash(ref) $seen and array(ref) $path contain the same information, but arrays are no good for lookup, and hashes are unordered which is no good for paths. Hence using both.
There is a potential optimisation there. I could just build the hash from the array at each level instead of passing it through. In fact, I'll try that later.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: Finding All Paths From a Graph From a Given Source and End Node
by eMBR_chi (Acolyte) on May 13, 2011 at 21:07 UTC | |
by BrowserUk (Patriarch) on May 13, 2011 at 21:32 UTC | |
by eMBR_chi (Acolyte) on May 21, 2011 at 17:37 UTC | |
by BrowserUk (Patriarch) on May 22, 2011 at 02:58 UTC | |
by eMBR_chi (Acolyte) on May 22, 2011 at 08:18 UTC | |
|