Questions tagged [floyd-warshall]

The Floyd-Warshall algorithm is an O(|V|^3) algorithm for computing all-pairs shortest paths in a directed weighted graph.

During the work of Floyd–Warshall algorithm all possible paths through the directed weighted graph between each pair of vertices are compared. The complexity is O(n^3) where n is a number of vertices.

Minimal pseudo code to get only shortest paths of a graph:

for k = 1 to n
  for i = 1 to n
    for j = 1 to n
      W[i][j] = min(W[i][j], W[i][k] + W[k][j])

Where W is a matrix (size n x n) which stores all shortest paths. At the start W is filled with infinity (any large number which exceeds the sum of weights of a graph). For each edge (u,v) of a graph the weight of the edge (u,v) has to be placed to the matrix W.

Algorithm is allowed path reconstruction.

This algorithm is effective for full-packed graph especially stored as connectivity matrix.

Wiki article about Floyd-Warshall algorithm

207 questions
0
votes
1 answer

Floyd-Warshall Shortest Path Algorithm Error

Problem Statement: https://www.hackerrank.com/challenges/floyd-city-of-blinding-lights Code: import scala.io.StdIn._ import scala.collection.mutable object Solution { def FloydWarshall(n: Int, adj: Array[Array[Int]]): Array[Array[Int]] = { …
Abhishek
  • 432
  • 5
  • 19
0
votes
0 answers

Shortest path between every pair of nodes in And/Or graph?

I have an AND/OR dependency graph where nodes are web services and there is an arc between two services S1-->S2 if some output of S1 are similar to some input of S2 The weight of the arc is a function of many parameters (example: execution time) I…
0
votes
1 answer

Time complexity of Floyd Warshall Algorithm on negative weight cycles

I know that there is no method to find minimum distance when there are negative weight cycles in a graph, there will be no meaning of minimum distance. My question is what will happen if we feed Floyd Warshall Algorithm with graphs having negative…
Rishabh Gupta
  • 389
  • 6
  • 19
0
votes
0 answers

Is there a way to apply the floyd Warshall to a graph containing OR and AND nodes in order to get the shortest path between vertices

I created an oriented dependency graph of semantique web service where nodes are web services and there is an edge between two services if they can be composed(the output of one are similares to the input of the other). the weight is a function…
0
votes
1 answer

Online Judge PS [Floyd_Warshal, C++]

I am solving this problem https://www.acmicpc.net/problem/1238# You can change the language by clicking the button The idea I came up with is to find the sum of the shortest distance from the Kth to the second and the second to the Kth so here is…
logan shin
  • 43
  • 2
  • 6
0
votes
1 answer

Advice and guidance for a rough program

I'm new to data structures and I have to build a rough version of Uber using graph, Floyd Warshall algorithm and search tree I think. Are there any similar problems and can I get some guidance on how to tackle this? Thanks
0
votes
1 answer

distance between nodes in floyd warshall

Thiswikipedia page explains the Floyd Warshall algorithm to find the shortest path between nodes in a graph. The wikipedia page uses the graph on the left of the image as a starting graph (prior to the first iteration when k = 0) and then shows…
Leahcim
  • 40,649
  • 59
  • 195
  • 334
0
votes
1 answer

Upside down Floyd–Warshall

I have a quick question. I know that this is a problem NP. If you receive the correct reversal algorithm Floyd-Warshall longest path between each pair of nodes?
xodos
  • 39
  • 1
  • 7
0
votes
0 answers

Graph theory: Best scalable solution when working with many vertexes

I've got a graph were each vertex represents a city. (identified by lat, lng properties) In between the vertexes (cities) are weighted edges, these represent predefined routes in between the cities. In between some vertexes we have multiple edges…
DiscoFever
  • 123
  • 8
0
votes
0 answers

Printing shortest path of Floyd Warshall

I'm struggling with finishing my Floyd-Warshall algorithm, I've tried to write my program based on wikipedia pseudocode, but it doesn't work as suposed. I create second matrix to store changes in route so that's my code: for (int w = 0; w <…
EyeMaze
  • 143
  • 2
  • 9
0
votes
2 answers

Parallel linq on floyd warshall

We were encountering this Graph problem and we needed to implement Floyd Warshall, So we did. Although we kinda disliked the algorithm because it is very slow. We would like to know if it's possible to apply parallel linq on the second loop, so we…
barthr
  • 430
  • 7
  • 15
0
votes
1 answer

Shortest path by minimum number of vertices

I have read about Floyd and Dijkstra, but they to find shortest path by minimum length of edges between nodes How can I find the shortest path in a directed graph by traversing the minimum number of nodes?
Roy
  • 277
  • 1
  • 5
  • 17
0
votes
2 answers

Calculate reachability for every vertex from adjacency list

Given an adjacency list Map> for a DAG, I want to calculate the reachability of every vertex (i.e. if there there is path from u to v). static Map> reachability(Map> adjList) {} I know it…
0
votes
2 answers

How to find the longest smallest path?

A frog wants to cross a river. There are 3 stones in the river she can jump to. She wants to choose among all possible paths the one that leads to the smallest longest jump. Ie. each of the possible paths will have one jump that is the longest. She…
user35202
  • 389
  • 1
  • 10
0
votes
1 answer

getting wrong output for Parallel Floyd Warshall Algorithm in OpenCL

#include #include #include /*#ifdef __APPLE__ #include #else*/ #include //#endif #define DATA_SIZE 16 using namespace std; const char *ProgramSource = "__kernel void…
Shubham Gupta
  • 227
  • 2
  • 9