graph-algorithm

Efficiently build a graph of words with given Hamming distance

谁说我不能喝 提交于 2019-12-04 10:22:20
问题 I want to build a graph from a list of words with Hamming distance of (say) 1, or to put it differently, two words are connected if they only differ from one letter ( lo l -> lo t ). so that given words = [ lol, lot, bot ] the graph would be { 'lol' : [ 'lot' ], 'lot' : [ 'lol', 'bot' ], 'bot' : [ 'lot' ] } The easy way is to compare every word in the list with every other and count the different chars; sadly, this is a O(N^2) algorithm. Which algo/ds/strategy can I use to to achieve better

Dividing a graph in three parts such the maximum of the sum of weights of the three parts is minimized

孤人 提交于 2019-12-04 09:32:34
I want to divide a graph with N weighted-vertices and N-1 edges into three parts such that the maximum of the sum of weights of all the vertices in each of the parts is minimized. This is the actual problem i am trying to solve, http://www.iarcs.org.in/inoi/contests/jan2006/Advanced-1.php I considered the following method /*Edges are stored in an array E, and also in an adjacency matrix for depth first search. Every edge in E has two attributes a and b which are the nodes of the edge*/ min-max = infinity for i -> 0 to length(E): for j -> i+1 to length(E): /*Call depth first search on the nodes

box stacking in graph theory

一世执手 提交于 2019-12-04 09:21:58
Please help me find a good solution for this problem. We have n boxes with 3 dimensions. We can orient them and we want to put them on top of another to have a maximun height. We can put a box on top of an other box, if 2 dimensions (width and lenght) are lower than the dimensions of the box below. For exapmle we have 3 dimensions w*D*h, we can show it in to (h*d,d*h,w*d,d*W,h*w,w*h) please help me to solve it in graph theory. in this problem we can not put(2*3)above(2*4) because it has the same width.so the 2 dimension shoud be smaller than the box Edit: Only works if boxes can not be rotated

Finding the n-degree neighborhood of a node

风流意气都作罢 提交于 2019-12-04 08:18:45
I'm new to networkx and actually a bit confused on how to efficiently find the n-degree neighborhood of a node. The n-degree neighborhood of a node v_i is the set of nodes exactly n hops away from v_i. Given a specified n, I need find the n-degree neighborhood for each node in the graph/network. Suppose I have the following graph and I want to find the n=1 neighborhood of node v1. That would be v2 and v3. Next suppose I want to find the n=2 neighborhood of node v1, then that would be v4. import networkx as nx G = nx.Graph() G.add_edges_from([('v1','v2'),('v2','v4'),('v1','v3')]) def

Surface reconstruction from 2 planar contours [closed]

时光毁灭记忆、已成空白 提交于 2019-12-04 07:46:25
There is a class of algorithms for triangulation between two planar contours. These algorithms try to make a "good triangulation" to fill a space between these contours: One of them ( Optimal surface reconstruction from planar contours ) is based on the dynamic programming technique and uses a cost function for determining which triangulation is acceptable according to the minimum cost. A minimal triangle area as a cost function makes a good result in most of cases ( Triangulation of Branching Contours using Area Minimization ), but, unfortunately, not in all of them. For example when you have

Finding simple path between two vertices in a tree (undirected simple graph)

烈酒焚心 提交于 2019-12-04 06:43:44
问题 Given two vertices (A and B) and a tree (G) (undirected simple graph) - Find the vertices in the simple path between A and B in G. The algorithm should run in O(V) complexity. for instance - find the vertices in the simple path between a and b: d<->k k<->a k<->b the answer should be : k I have tried to modify BFS to accomplish the goal but it doesn't seem to work so far. Any suggestions? 回答1: If the problem is reconstructing the path after you found the distance, adjust the BFS in the

Euclidean Minimum Spanning Tree Without Triangulation

爱⌒轻易说出口 提交于 2019-12-04 05:51:20
问题 I was looking through some text about finding the EMST (Euclidean MST) using Delaunay triangulation technique, but also read somewhere that the EMST can be found through a sweep line algorithm. Since this would easier implementing, I would like to implement this rather than using a existing library. Can anyone guide me/ direct me to a link to a (possibly free) paper/source that has this algorithm explained? 回答1: From this and going by the abstracts, this and this should get you started. They

AStar - explanation of name

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:53:28
I am looking for an explanation why the AStar / A* algorithm is called AStar. All similar (shortest path problem) algorithms are often named like its developer(s), so what is AStar standing for? There were algorithms called A1 and A2. Later, it was proved that A2 was optimal and in fact also the best algorithm possible, so he gave it the name A* which symbolically includes all possible version numbers. Source: In 1964 Nils Nilsson invented a heuristic based approach to increase the speed of Dijkstra's algorithm. This algorithm was called A1. In 1967 Bertram Raphael made dramatic improvements

Detecting all circles in a graph

淺唱寂寞╮ 提交于 2019-12-03 20:44:33
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("8", new String[] {"6"}); map.put("9", new String[] {"10"}); map.put("10", new String[] {"5"}); map.put(

Detecting cycles in an adjacency matrix

☆樱花仙子☆ 提交于 2019-12-03 19:11:29
问题 Let A be the adjacency matrix for the graph G = (V,E) . A(i,j) = 1 if the nodes i and j are connected with an edge, A(i,j) = 0 otherwise. My objective is the one of understanding whether G is acyclic or not. A cycle is defined in the following way: i and j are connected: A(i,j) = 1 j and k are connected: A(j,k) = 1 k and i are connected: A(k,i) = 1 I have implemented a solution which navigates the matrix as follows: Start from an edge (i,j) Select the set O of edges which are outgoing from j