# Search Results

• ### bellman forge, dijkstra's, prim's algorithm, kruskals, directed acrylic graph

##### - by bfpri
What are some real life examples where each one of these are used?

• ### Am I right about the differences between Floyd-Warshall, Dijkstra's and Bellman-Ford algorithms?

##### - by Programming Noob
I've been studying the three and I'm stating my inferences from them below. Could someone tell me if I have understood them accurately enough or not? Thank you. Dijkstra's algorithm is used only when you have a single source and you want to know the smallest path from one node to another, but fails in cases like this Floyd-Warshall's algorithm is used when any of all the nodes can be a source, so you want the shortest distance to reach any destination node from any source node. This only fails when there are negative cycles (this is the most important one. I mean, this is the one I'm least sure about:) 3.Bellman-Ford is used like Dijkstra's, when there is only one source. This can handle negative weights and its working is the same as Floyd-Warshall's except for one source, right? If you need to have a look, the corresponding algorithms are (courtesy Wikipedia): Bellman-Ford: procedure BellmanFord(list vertices, list edges, vertex source) // This implementation takes in a graph, represented as lists of vertices // and edges, and modifies the vertices so that their distance and // predecessor attributes store the shortest paths. // Step 1: initialize graph for each vertex v in vertices: if v is source then v.distance := 0 else v.distance := infinity v.predecessor := null // Step 2: relax edges repeatedly for i from 1 to size(vertices)-1: for each edge uv in edges: // uv is the edge from u to v u := uv.source v := uv.destination if u.distance + uv.weight < v.distance: v.distance := u.distance + uv.weight v.predecessor := u // Step 3: check for negative-weight cycles for each edge uv in edges: u := uv.source v := uv.destination if u.distance + uv.weight < v.distance: error "Graph contains a negative-weight cycle" Dijkstra: 1 function Dijkstra(Graph, source): 2 for each vertex v in Graph: // Initializations 3 dist[v] := infinity ; // Unknown distance function from 4 // source to v 5 previous[v] := undefined ; // Previous node in optimal path 6 // from source 7 8 dist[source] := 0 ; // Distance from source to source 9 Q := the set of all nodes in Graph ; // All nodes in the graph are 10 // unoptimized - thus are in Q 11 while Q is not empty: // The main loop 12 u := vertex in Q with smallest distance in dist[] ; // Start node in first case 13 if dist[u] = infinity: 14 break ; // all remaining vertices are 15 // inaccessible from source 16 17 remove u from Q ; 18 for each neighbor v of u: // where v has not yet been 19 removed from Q. 20 alt := dist[u] + dist_between(u, v) ; 21 if alt < dist[v]: // Relax (u,v,a) 22 dist[v] := alt ; 23 previous[v] := u ; 24 decrease-key v in Q; // Reorder v in the Queue 25 return dist; Floyd-Warshall: 1 /* Assume a function edgeCost(i,j) which returns the cost of the edge from i to j 2 (infinity if there is none). 3 Also assume that n is the number of vertices and edgeCost(i,i) = 0 4 */ 5 6 int path[][]; 7 /* A 2-dimensional matrix. At each step in the algorithm, path[i][j] is the shortest path 8 from i to j using intermediate vertices (1..k-1). Each path[i][j] is initialized to 9 edgeCost(i,j). 10 */ 11 12 procedure FloydWarshall () 13 for k := 1 to n 14 for i := 1 to n 15 for j := 1 to n 16 path[i][j] = min ( path[i][j], path[i][k]+path[k][j] );

• ### Best Order to traverse a Bellman-Ford Algorithm to achieve min. number of iterations?

##### - by awhateverp
Hey everybody, What is the Best oder of traversing edges within Bellman-Ford algorithm in Order to achieve a min. number of iterations necessary.? thx in advance, Andreas

• ### Segmentation fault on MPI, runs properly on OpenMP

##### - by Bellman
Hi, I am trying to run a program on a computer cluster. The structure of the program is the following: PROGRAM something ... CALL subroutine1(...) ... END PROGRAM SUBROUTINE subroutine1(...) ... DO i=1,n CALL subroutine2(...) ENDDO ... END SUBROUTINE SUBROUTINE subroutine2(...) ... CALL subroutine3(...) CALL subroutine4(...) ... END SUBROUTINE The idea is to parallelize the loop that calls subroutine2. Main program basically only makes the call to subroutine1 and only its arguments are declared. I use two alternatives. On the one hand, I write OpenMP clauses arround the loop. On the other hand, I add an IF conditional branch arround the call and I use MPI to share the results. In the OpenMP case, I add CALL KMP_SET_STACKSIZE(402653184) at the beginning of the main program and I can run it with 8 threads on an 8 core machine. When I run it (on the same 8 core machine) with MPI (either using 8 or 1 processors) it crashes just when makes the call to subroutine3 with a segmentation fault (signal 11) error. If I comment subroutine4, then it doesn't crash (notice that it crashed just when calling subroutine3 and it works when commenting subroutine4). I compile with mpif90 using MPICH2 libraries and the following flags: -O3 -fpscomp logicals -openmp -threads -m64 -xS. The machine has EM64T architecture and I use a Debian Linux distribution. I set ulimit -s hard before running the program. Any ideas on what is going on? Has it something to do with stack size? Thanks in advance

• ### Introduction aux algorithmes et aux structures de données, un cours par Thibaut Cuvelier

En 1976, le livre Algorithms + Data Structures = Programs paraît : le postulat posé par ce titre est bien qu'un algorithme n'est rien s'il n'a pas de structure de données appropriée pour stocker ses données. On étudiera, dans cette introduction, tant les algorithmes principaux (tri, graphes %u2013 le bien connu Dijkstra mais aussi Bellman-Ford pour la recherche de plus court chemin) que des structures de données très fréquentes sur lesquelles viennent se construire des solutions élaborées à des problèmes complexes (pile, file, dictionnaire, etc.).

• ### Implementation of any Hamiltonian Path Problem algorithm

##### - by Julien
Hi all ! Here is my problem : I have an array of points, the points have three properties : the "x" and "y" coordinates, and a sequence number "n". The "x" and "y" are defined for all the points, the "n" are not. You can access and write them calling points[i]-x, points[i]-y, points[i]-n. i.e. : points[i]->n = var var = points[i]->n So the title maybe ruined the surprise, but I'm looking for a possible implementation of a solution to the Hamiltonian path problem : I need to set the "n" number of each point, so that the sequence is the shortest path (not cycle, the edges have to be disjoint) that goes exactly once through each point. I looked for a solution and I found The Bellman Ford Algorithm but I think it doesn't work since the problem doesn't specify that it has to go through all of the points is it correct ? If it is, does somebody has another algorithm and the implementation ? If the Bellman Ford Algorithm works, how would I implement it ? Thanks a lot, Julien

• ### I am trying to build a list of limitations of all graph algorithms

##### - by Jack
Single Source shortest Path Dijkstra's - directed and undirected - works only for positive edge weights - cycles ?? Bellman Ford - directed - no cycles should exist All source shortest path Floyd Warshall - no info Minimum Spanning Tree ( no info about edge weights or nature of graph or cycles) Kruskal's Prim's - undirected Baruvka's

• ### Boost graph libraries: setting edge weight values

##### - by AndyUK
I am investigating the use of the boost graph libraries in order to apply them to various network problems I have in mind. In the examples I have been looking at the graph edge values ("weights") are always initialized as integers, such as in these Bellman-Ford and Kruskal algorithms eg: int weights[] = { 1, 1, 2, 7, 3, 1, 1, 1 }; My problem is if I try and change the weights to double, I get a heap of warning messages about conversions etc, which so far I have not been able to figure out how to overcome. Does anyone see a way around this?

• ### Calculating Divergent Paths on Subtending Rings

##### - by Russ
I need to calculate two paths from A to B in the following graph, with the constraint that the paths can't share any edges: hmm, okay, can't post images, here's a link. All edges have positive weights; for this example I think we can assume that they're equal. My naive approach is to use Djikstra's algorithm to calculate the first path, shown in the second graph in the above image. Then I remove the edges from the graph and try to calculate the second path, which fails. Is there a variation of Djikstra, Bellman-Ford (or anything else) that will calculate the paths shown in the third diagram above? (Without special knowledge and removal of the subtending link, is what I mean)

• ### Inventory Management OOP design

##### - by rgamber
This was an OOP design and implementation interview question, which I came across on glassdoor.com. Design and implement a inventory management system to minimize the number of missed delivery dates while keeping costs to the company low. Of course there is no right answer to this, but I am not sure I understand the question correctly and am wondering what would be a good answer. Is this as simple as creating an undirected graph with nodes as the delivery points, and edges having weights as the cost of the delivery, and then use a single-source-shortest-path algorithm (like Dijkstras, or Bellman-Ford) on the graph? Not sure if this type of question should be asked here,so let me know and I will delete it.