graph algorithms: reachability from adjacency map -


I have a dependency graph, which I used to call map & lt; Node, collection & lt; Node & gt; & Gt; (in Java-Speech, or f (node ​​n) - & gt; Collection [node] as a function; it is a given node n Mapping from is a collection of nodes which depends on n ) graph is potentially cyclic *.

Looking at the list of nodes list , I would like to solve it: i.e. map & lt; Node, set & lt; Node & gt; & Gt; ;

Example:

Example For,

  (x -> y stands for node y depends on node x) n1 - & gt; N 2 N 2 - & gt; N3 N3 - & gt; N1N3 - & gt; N5N4 - & gt; N2N4 - & gt; N5 N6 - & gt; N1N7 - & gt; N1   

presented as adjacent map {n1: [n2], n2: [n3], n3: [n1, n5], n4: [n2, n5] Can be done], N6: [N1], N7: [N1]} .

If the badlist = [n4, n5, n1] then badmap = {n4: [n4, n2, n3, n1, n5], n5: [n5] ], N1: [n1, n2, n3, n5]} .

Graph Algorithms rush as well as references to the online search, so if I can point to an efficient algorithm description for accessibility, so I appreciate it. (Some examples that not are helpful to me, because the algorithm is to determine whether a particular node A is accessible from a specific node B.)

* Cyclic: If you are curious, that's because it represents the type of C / C + +, and can be a member of the structures that give the signal to the structure in question.

In Python:

  def accessible (article, balllist): Badmap = {} in the badge list for the root: stack = [root] visit = set () stack: V = stack.pop () if the visit is visited: Continue to visit stack.extend (article [V]) Done.ad (v) badmap [root] = visited badmeap visited    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -