c#,directed-graph,cyclic-graph

Not sure I'm understanding correctly because it seems like you've already solved this with your visited HashSet. Just make it a local variable in Init and return that as the result of the operation: class Program { static Dictionary<string, HashSet<string>> groupMembers = new Dictionary<string, HashSet<string>> { { "G4", new HashSet<string>...

algorithm,social-networking,graph-algorithm,sampling,directed-graph

You can treat the undirected graph like a directed graph for the purposes of sampling. Any sampling strategy for a directed graph should work assuming it allows cycles. You simply want to sample the nodes and edges, so any edges that become part of the sample just accept the edge...

As originally posted in the question by the TS: I don't need help anymore, somehow I solved this problem right after I posted this question. SELECT p.first_location, p.second_location, ( SELECT COUNT (*) FROM ( SELECT q.first_location, q.second_location FROM connections AS c WHERE p.first_location = q.second_location and p.second_location = q.forst_location )...

algorithm,graph,dijkstra,directed-graph

Remove the negative edge (u, v), run Dijkstra twice: once starting at s (D1) and once starting at v (D2) The shortest path between s and t is: min(D1[t], D1[u]+D2[t]+w(u, v))....

algorithm,pseudocode,directed-graph,topological-sort

There's no particular reason to use a stack as opposed to some other kind of collection. If we pop elements nondeterministically, then we can realize all possible topological orders. Thus, the topological order is unique if and only if the collection contains one element each time we pop (except when...

in Edit 1 Section : you are always getting "Cycle doesnt exists" because you are not returning correct answer when it found. the only error in your program is in the condition checking of if(isCycle[w] == -1) return checkCycle(w, n); before this you were not returning the correct answer so...

javascript,d3.js,force-layout,bounding-box,directed-graph

I found out how it goes. If anybody wants to add a bounding box to this mobile-patent-suits example (http://bl.ocks.org/mbostock/1153292), this might be helpful: function tick() { //circle.attr("transform", transform); //no need for this anymore circle.attr("cx", function(d) { return d.x = Math.max(8, Math.min(300 - 8, d.x)); }) .attr("cy", function(d) { return d.y...

java,algorithm,graph,directed-graph

Well, not really - you cannot make it significantly more efficient, because the output size itself is huge. The number of paths is exponential in the number of nodes, have a look at this simple example: V = {a, b, c}, E = {(a,b), (a,c), (b,c)} This looks pretty simple,...

algorithm,graph,directed-graph,bfs

you can use the following pseudo-code: ( you can save the distance from the source node in BFS by setting the distance property of each node to father.distance + 1, and the initial node has a distance of 0. also the initial distance for every node is infinite) BFS(G,targetNode), remember...

java,design-patterns,builder,fluent-interface,directed-graph

The problem is that the builder is a chain of methods, while you want to build a graph with cycles. You'll need to backtrack, and to do that it is necessary to refer to previous nodes either explicitely (using their label) or implictly, e.g: Graph graph = GraphBuilder.newGraph() .addVertex("A") .edgeName("")...

algorithm,graph,directed-graph,dfs,bfs

If you want to figure out your digraph is strongly connected there are several algorithm for that and in wiki you can find this three: Kosaraju's algorithm Tarjan's algorithm Path-based strong component algorithm If you want to check if your digraph is just connected or not, you can simply assume...

scala,graph,directed-graph,undirected-graph

There is no real difference in the implementation of an Edge, in both cases just the two connected nodes need to be specified. The difference would pop-up when you wanted to implement something else where the meaning of an edge needs interpretation. For instance, if you had a method areConnected(a:...

javascript,matrix,directed-graph,protovis

Well!! I spent couple of hours to make my own HTML table matrix. data.nodedetail.forEach(function(node){ table += "<tr><td>"+ node.title + "</td>"; var emptycols =""; i++; for(j=0;j<i;j++){ emptycols += "<td></td>"; } if(i!=size){ emptycols += "<td colspan='"+ (size - j) +"'>"+node.title+"</td>";} table += emptycols + "</tr>"; }); table = "<table>"+ table + "</table>";...