tarjans-algorithm

Tarjan's strongly connected components algorithm in python not working

我怕爱的太早我们不能终老 提交于 2019-12-03 03:12:55
I implemented the Tarjan's strongly connected components algorithm, according to wikipedia , in Python, but it isn't working. The algorithm is quite short and I cannot find any difference, so I cannot tell why it isn't working. I tried to check the original paper, but could not find it. Here is the code. def strongConnect(v): global E, idx, CCs, c, S idx[v] = (c, c) #idx[v][0] for v.index # idx[v][1] for v.lowlink c += 1 S.append(v) for w in [u for (v2, u) in E if v == v2]: if idx[w][0] < 0: strongConnect(w) # idx[w] = (idx[w][0], min(idx[v][1], idx[w][1])) #fixed, thx idx[v] = (idx[v][0], min

Functional implementation of Tarjan's Strongly Connected Components algorithm

天涯浪子 提交于 2019-12-03 02:49:35
问题 I went ahead and implemented the textbook version of Tarjan's SCC algorithm in Scala. However, I dislike the code - it is very imperative/procedural with lots of mutating states and book-keeping indices. Is there a more "functional" version of the algorithm? I believe imperative versions of algorithms hide the core ideas behind the algorithm unlike the functional versions. I found someone else encountering the same problem with this particular algorithm but I have not been able to translate

Tarjan's Algorithm: Time Complexity and slight modification possibility

戏子无情 提交于 2019-12-02 04:11:49
This question is related to but not the same as the one recently asked here . I just read the Wikipedia psuedocode . algorithm tarjan is input: graph G = (V, E) output: set of strongly connected components (sets of vertices) index := 0 S := empty for each v in V do if (v.index is undefined) then strongconnect(v) end if end for function strongconnect(v) // Set the depth index for v to the smallest unused index v.index := index v.lowlink := index index := index + 1 S.push(v) // Consider successors of v for each (v, w) in E do if (w.index is undefined) then // Successor w has not yet been visited

Tarjan cycle detection help C#

狂风中的少年 提交于 2019-11-30 04:20:16
Here is a working C# implementation of tarjan's cycle detection. The algorithm is found here: http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm public class TarjanCycleDetect { private static List<List<Vertex>> StronglyConnectedComponents; private static Stack<Vertex> S; private static int index; private static DepGraph dg; public static List<List<Vertex>> DetectCycle(DepGraph g) { StronglyConnectedComponents = new List<List<Vertex>>(); index = 0; S = new Stack<Vertex>(); dg = g; foreach (Vertex v in g.vertices) { if (v.index < 0) { strongconnect(v); } } return

Tarjan cycle detection help C#

北城余情 提交于 2019-11-29 01:38:06
问题 Here is a working C# implementation of tarjan's cycle detection. The algorithm is found here: http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm public class TarjanCycleDetect { private static List<List<Vertex>> StronglyConnectedComponents; private static Stack<Vertex> S; private static int index; private static DepGraph dg; public static List<List<Vertex>> DetectCycle(DepGraph g) { StronglyConnectedComponents = new List<List<Vertex>>(); index = 0; S = new Stack