graph-algorithm

Subgraph enumeration

[亡魂溺海] 提交于 2019-11-30 02:40:19
问题 What is an efficient algorithm for the enumeration of all subgraphs of a parent graph. In my particular case, the parent graph is a molecular graph, and so it will be connected and typically contain fewer than 100 vertices. Edit: I am only interested in the connected subgraphs. 回答1: This question has a better answer in the accepted answer to this question. It avoids the computationally complex step marked "you fill in above function" in @ninjagecko's answer. It can deal efficiently with

Algorithm for finding a Hamilton Path in a DAG

懵懂的女人 提交于 2019-11-29 22:52:03
I am referring to Skienna's Book on Algorithms. The problem of testing whether a graph G contains a Hamiltonian path is NP-hard , where a Hamiltonian path P is a path that visits each vertex exactly once. There does not have to be an edge in G from the ending vertex to the starting vertex of P , unlike in the Hamiltonian cycle problem. Given a directed acyclic graph G ( DAG ), give an O(n + m) time algorithm to test whether or not it contains a Hamiltonian path. My approach, I am planning to use DFS and Topological sorting . But I didn't know how to connect the two concepts in solving the

How to implement Prim's algorithm with a Fibonacci heap?

为君一笑 提交于 2019-11-29 20:00:18
I know Prim's algorithm and I know its implementation but always I skip a part that I want to ask now. It was written that Prim's algorithm implementation with Fibonacci heap is O(E + V log(V)) and my question is: what is a Fibonacci heap in brief? How is it implemented? And How can you implement Prim's algorithm with a Fibonacci heap? A Fibonacci heap is a fairly complex priority queue that has excellent amoritzed asymptotic behavior on all its operations - insertion, find-min, and decrease-key all run in O(1) amortized time, while delete and extract-min run in amortized O(lg n) time. If you

Obtaining connected components in R

冷暖自知 提交于 2019-11-29 10:36:05
I have a matrix with values 0 or 1 and I would like to obtain a list of groups of adjacent 1's. For example, the matrix mat = rbind(c(1,0,0,0,0), c(1,0,0,1,0), c(0,0,1,0,0), c(0,0,0,0,0), c(1,1,1,1,1)) > mat [,1] [,2] [,3] [,4] [,5] [1,] 1 0 0 0 0 [2,] 1 0 0 1 0 [3,] 0 0 1 0 0 [4,] 0 0 0 0 0 [5,] 1 1 1 1 1 should return the following 4 connected components: C1 = {(1,1);(2,1)} C2 = {(2,4)} C3 = {(3,3)} C4 = {(5,1);(5,2);(5,3);(5,4);(5,5)} Does anybody has an idea of how to do it fast in R? My real matrix is indeed rather large, like 2000x2000 (but I expect that the number of connected

Relaxation of an edge in Dijkstra's algorithm

左心房为你撑大大i 提交于 2019-11-29 10:35:51
问题 What does relaxation of an edge mean in the context of graph theory ? I came across this while studying up on Dijkstra's algorithm for single source shortest path. 回答1: Here's a nice description of the Algorithm that also explains the notion of relaxation. The notion of "relaxation" comes from an analogy between the estimate of the shortest path and the length of a helical tension spring, which is not designed for compression. Initially, the cost of the shortest path is an overestimate,

Relationship between BFS and topological sort

China☆狼群 提交于 2019-11-29 07:52:21
Topological sort can be done using both a DFS(having edges reversed) and also using a queue . A BFS can also be done using a queue . Is there any relationship between the way elements are stored and retrieved while using queue for a BFS to that when used a queue for topological sorting . Clarification will be helpful . Thanks. No, there is not necessarily any relationship. I assume you are referring to the algorithm by Kahn from wikipedia/Topological_sorting#Algorithms , which wikipedia notes: Note that, reflecting the non-uniqueness of the resulting sort, the structure S can be simply a set

Topological sort of cyclic graph with minimum number of violated edges

本秂侑毒 提交于 2019-11-29 07:11:00
问题 I am looking for a way to perform a topological sorting on a given directed unweighted graph, that contains cycles. The result should not only contain the ordering of vertices, but also the set of edges, that are violated by the given ordering. This set of edges shall be minimal. As my input graph is potentially large, I cannot use an exponential time algorithm. If it's impossible to compute an optimal solution in polynomial time, what heuristic would be reasonable for the given problem? 回答1:

Stable topological sort

橙三吉。 提交于 2019-11-29 05:48:40
问题 Let say I have a graph where the nodes is stored in a sorted list. I now want to topological sort this graph while keeping the original order where the topological order is undefined. Are there any good algorithms for this? 回答1: One possibility is to compute the lexicographically least topological order. The algorithm is to maintain a priority queue containing the nodes whose effective in-degree (over nodes not yet processed) is zero. Repeatedly dequeue the node with the least label, append

OpenGL ES 2.0 Vertex Transformation Algorithms

送分小仙女□ 提交于 2019-11-29 04:19:52
I'm developing an image warping iOS app with OpenGL ES 2.0. I have a good grasp on the setup, the pipeline, etc., and am now moving along to the math. Since my experience with image warping is nil, I'm reaching out for some algorithm suggestions. Currently, I'm setting the initial vertices at points in a grid type fashion, which equally divide the image into squares. Then, I place an additional vertex in the middle of each of those squares. When I draw the indices, each square contains four triangles in the shape of an X. See the image below: After playing with photoshop a little, I noticed

Finding path with maximum minimum capacity in graph

血红的双手。 提交于 2019-11-29 03:07:38
问题 I am helping a friend with a work related project where, he needs to calculate the maximum capacity from a node a to a node b, where the edge has a capacity. However the maximum capacity in a path from a to b is limited by the edge with the lowest capacity. Let me try to explain with a simple sample So the graph is a directed graph with weighted edges, and it can be cyclic. The path with the highest capacity would be s->b->t and have the capacity of 250, since that edge is setting the limit.