graph-algorithm

Algorithm for minimum diameter spanning tree

早过忘川 提交于 2019-12-01 20:38:17
Given a undirected and connected graph G, find a spanning tree whose diameter is the minimum. singhsumit linked the relevant paper by Hassin and Tamir , entitled "On the minimum diameter spanning tree problem", but his answer is currently deleted. The main idea from the paper is that finding a minimum diameter spanning tree in an undirected graph can be accomplished by finding the "absolute 1-center" of the graph and returning a shortest path tree rooted there. The absolute 1-center is the point, either on a vertex or an edge, from which the distance to the furthest vertex is minimum. This can

traveling salesman without return and with given start and end cities

梦想的初衷 提交于 2019-12-01 14:34:05
I am looking for the name of the following problem: traveling salesman problem (visit each city exactly once) but without returning to the start city and with visiting a given city at the end. In other words, I would like to specify the start and end cities, and I don't want to go back to the start city. Thanks!!! I doubt this has its own name, as it's trivially isomorphic to the normal TSP. From standard TSP to this: Given a directed weighted graph for TSP, with a start/end node, split the start/end node into a start node and an end node, with all the outgoing edges on the start node and all

Find all simple path from node A to node B in direct weighted graph with the sum of weighs less a certain value?

心已入冬 提交于 2019-12-01 14:13:08
I have a directed weighted graph G=(V,E), which may have loops . I am trying to determine the best time efficient algorithm to accomplish task: t o find all simple path in G between source and target node with total weight of edges in this path less than certain value (for convenience we denote this value as PATH_WEIGHT_LIMIT) All weights is positive and can be float. So, a prototype of my function will be: def find_paths(G, source, target, path_weight_limit) Result paths may overlap, its fine. Much like those discussed here, e.g.: algorithm for finding NUMBER of distinct paths from A to B in

Approximation Algorithm for non-intersecting paths in a grid

戏子无情 提交于 2019-12-01 08:56:33
I recently came across this question and thought I could share it here, since I wasn't able to get it. We are given a 5*5 grid numbered from 1-25, and a set of 5 pairs of points,that are start and end points of a path on the grid. Now we need to find 5 corresponding paths for the 5 pairs of points, such that no two paths should overlap. Also note that only vertical and horizontal moves are allowed. Also the combined 5 path should cover the entire grid. For example we are given the pair of points as: P={1,22},{4,17},{5,18},{9,13},{20,23} Then the corresponding paths will be 1-6-11-16-21-22 4-3

What is an efficient way of traversing a graph with bfs using map reduce?

浪子不回头ぞ 提交于 2019-12-01 05:43:42
问题 This was an interview question I got asked by a recruiter, the problem is basically to calculate the shortest path of all node to every node, and my solution was the following initiate all possible edges (without reverse A - B is the same as B-A) Each node will be represent in the following (src, cost, current_list, dest) , the src and dest is basically all the possible edges we initiate earlier Map: for each edge you traverse, you duplicate your tuple and add the current traversed node to

Approximation Algorithm for non-intersecting paths in a grid

£可爱£侵袭症+ 提交于 2019-12-01 05:43:33
问题 I recently came across this question and thought I could share it here, since I wasn't able to get it. We are given a 5*5 grid numbered from 1-25, and a set of 5 pairs of points,that are start and end points of a path on the grid. Now we need to find 5 corresponding paths for the 5 pairs of points, such that no two paths should overlap. Also note that only vertical and horizontal moves are allowed. Also the combined 5 path should cover the entire grid. For example we are given the pair of

Bellman ford queue based approach from Sedgewick and Wayne - Algorithms, 4th edition

寵の児 提交于 2019-12-01 03:50:02
问题 I was studying queue-based approach for Bellman-Ford algorithm for single source shortest path from Robert Sedgewick and Kevin Wayne - Algorithms, 4th edition source code for algorithm from book is present at this link http://algs4.cs.princeton.edu/44sp/BellmanFordSP.java. I have two points one is a doubt and other is code improvement suggestion. In above approach following is code for relax method for relaxing distance to vertices. for (DirectedEdge e : G.adj(v)) { int w = e.to(); if (distTo

Finding all possible paths of n length in hexagonal grid

▼魔方 西西 提交于 2019-11-30 22:52:36
Assume that a function takes s (origin hexagon), f (target hexagon) and n (length of the path) values as parameters and outputs list of all possible paths that has n length. To visualize the problem please check the figure below: Let's say our origin ( s ) is the red dotted hex (2, 3) and the target ( f ) is the blue dotted one (5, 2) . We want to reach blue dotted hex in 5 steps ( n = 5 ). Also consider that if a walk reaches a specific hex, it may stay in that hex as well in the next step. In other words, one of the possible paths can be (3, 2) - (4, 2) - (5, 2) - (5, 2) - (5, 2) . It is

Subgraph enumeration

强颜欢笑 提交于 2019-11-30 19:08:10
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. Andrew Rose 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 compounds where there are several rings. See the linked question for the full details, but here's

An interesting graph task

给你一囗甜甜゛ 提交于 2019-11-30 18:32:36
问题 There is a tree with n vertices. We are asked to calculate minimum size of a multiset S such for each edge (u,v) in the tree at least one of the following holds: u ∈ S v ∈ S there are at least two vertices in S, each of which is adjacent to u or v. Since S is a multiset, a vertex may be in S multiple times. My hunch is the following. First of all, we take into consideration the following fact: in optimal solution each vertex is in S at most twice. So we can traverse tree in post-order