graph-algorithm

Detect if there exists a cycle in an undirected graph

北城余情 提交于 2019-12-11 03:07:55
问题 My question is concerned with DETECTING if there exists a cycle. I don't care where the cycle occurs but only if there exist a cycle. In particular, I am working on the implementation of a (maximally) spanning tree algorithm. I have sorted the edges in descending order and then I pick one edge at the time and put it in the set of the graph edges IFF it doesn't cause a cycle. I have found out that for undirected graphs in only enough to check if no_of_edges > no_of_vertices - 1 . Is this right

visualizing RDF query result

元气小坏坏 提交于 2019-12-11 03:03:24
问题 My SPARQL Query returns a set of results, I want to visualize the Query results using an RDF Visualization algorithm, such that the results are related together and also I retrieve some more info about it. Example: if My domain is Movie industry, and I query about all movies directed by James Cameron, I get about 10 or 11 results, something like, 'The Terminator' 'Rambo: First Blood Part II' 'Aliens' 'The Abyss' 'Terminator 2: Judgment Day ' 'True Lies' 'Titanic' 'Avatar' I want to make a

Tarjan's algorithm: do lowest-links have to be similar for two or more nodes to be inside the same SCC

三世轮回 提交于 2019-12-10 20:28:53
问题 I'm having some trouble with a homework question involving using Tarjan's algorithm on a provided graph to find the particular SCC's for that graph. While (according to my professor) I have found the correct SCC's by using the pseudo-code algorithm found here, some of the nodes in my SCC's do not share the same lowest-link number as the root node for that SCC. From what I can gather from the pseudo-code, this is because if an un-referenced node i (which is the input node for the current

Finding all paths between two nodes on a DAG

喜夏-厌秋 提交于 2019-12-10 19:38:03
问题 I have a DAG that has the following adjacency list L | G, B, P G | P, I B | I P | I I | R R | \ I want to find all paths from L to R . I know that I have to do some kind of DFS, and this is what I have so far. (Excuse the Javascript) function dfs(G, start_vertex) { const fringe = [] const visited = new Set() const output = [] fringe.push(start_vertex) while (fringe.length != 0) { const vertex = fringe.pop() if (!visited.has(vertex)) { output.push(vertex) for (neighbor in G[vertex].neighbors)

Check for cycles whose weights don't sum up to 0

青春壹個敷衍的年華 提交于 2019-12-10 18:32:26
问题 I have a connected graph g with n vertices and m edges. Each edge can be traversed from both directions, while traversing them in one direction their weight is positive, traverse them in the other direction and their weight is negative. So for every edge u -> v with weight w there exists an edge v -> u with weight -w . My goal: For a given vertex v , check if there exists a path back to v (a cycle) so that the sum of the edge weights of that path is not equal to 0 . If such a path exists then

Shortest path in a grid between two points. With a catch

痞子三分冷 提交于 2019-12-10 17:04:03
问题 I have this problem where I have to find the shortest path in an NxM grid from point A (always top left) to point B (always bottom right) by only moving right or down. Sounds easy, eh? Well here's the catch: I can only move the number shown on the tile I'm sitting on at the moment. Let me illustrate: 2 5 1 2 9 2 5 3 3 3 1 1 4 8 2 7 In this 4x4 grid the shortest path would take 3 steps, walking from top left 2 nodes down to 3, and from there 3 nodes right to 1, and then 1 node down to the goal

Finding right triangle coordinates in binary array

那年仲夏 提交于 2019-12-10 11:56:45
问题 Say I have an MxN binary matrix. It is not necessarily sparse. I'm interested in finding the coordinates of the apexes of all of the right triangles in the array. By right triangle, I mean: pretend that the 1 or True values in the matrix are vertices of triangles, and the 0's or False elements are null. Then a right triangle is an arrangement that visually forms a right triangle. By apex I mean the vertex which corresponds to the right angle of the triangle. E.g. in the following 5x6 array: 0

Optimal distribution of power plants on a city

China☆狼群 提交于 2019-12-10 11:19:23
问题 I've searched both Google and Stack Overflow for an answer to my problem but I can't find one. I need to find the optimal distribution for the power network of a city. The city is represented by a connected graph. I want to distribute power plants among some of those nodes in order to cover all of them in the electrical grid. The problem being that every power plant has a certain "range" (it can only cover for example in a "radius" of two nodes). My program needs to find the minimum number of

Detecting all circles in a graph

痞子三分冷 提交于 2019-12-09 13:42:28
问题 I have a directed graph stored in a Map data structure, where the key is the node's ID and the [value] is the array of the nodeIds of the nodes which are pointed by the key node. Map<String, String[]> map = new HashMap<String, String[]>(); map.put("1", new String[] {"2", "5"}); map.put("2", new String[] {"3"}); map.put("3", new String[] {"4"}); map.put("4", new String[] {"4"}); map.put("5", new String[] {"5", "9"}); map.put("6", new String[] {"5"}); map.put("7", new String[] {"6"}); map.put(

Finding nearest neighbours of a triangular tesellation

旧街凉风 提交于 2019-12-09 07:46:15
问题 I have a triangular tessellation like the one shown in the figure. Given N number of triangles in the tessellation, I have a N X 3 X 3 array which stores (x, y, z) coordinates of all three vertices of each triangle. My goal is to find for each triangle the neighbouring triangle sharing the same edge. The is an intricate part is the whole setup that I do not repeat the neighbour count. That is if triangle j was already counted as a neighbour of triangle i , then triangle i should not be again