Given a directed and strongly connected graph with non negative edge weighs. We define mean weight of a cycle as the summation of all the edge weights of the cycle divided by the no. of edges. Our task is to find the minimum mean weight among all the directed cycles of the graph.
Method to find the smallest mean weight value cycle efficiently
Step 1: Choose first vertex as source. Step 2: Compute the shortest path to all other vertices on a path consisting of k edges 0 <= k <= V where V is number of vertices. This is a simple dp problem which can be computed by the recursive solution dp[k][v] = min(dp[k][v], dp[k-1][u] + weight(u,v) where v is the destination and the edge(u,v) should belong to E Step 3: For each vertex calculate max(dp[n][v]-dp[k][v])/(n-k) where 0<=k<=n-1 Step 4: The minimum of the values calculated above is the required answer.
Please refer solution of problem 9.2 here for proof that above steps find minimum average weight.
Here the graph with no cycle will return value as -1.
Introduction to Algorithms Third Edition page 681 by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein
This article is contributed by Ayush Jha. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find minimum weight cycle in an undirected graph
- Check if there is a cycle with odd weight sum in an undirected graph
- Find the weight of the minimum spanning tree
- Remove all outgoing edges except edge with minimum weight
- Boruvka's algorithm for Minimum Spanning Tree
- Karger’s algorithm for Minimum Cut | Set 2 (Analysis and Applications)
- Karger's algorithm for Minimum Cut | Set 1 (Introduction and Implementation)
- Reverse Delete Algorithm for Minimum Spanning Tree
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- 0-1 BFS (Shortest Path in a Binary Weight Graph)
- k'th heaviest adjacent node in a graph where each vertex has weight
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Hamiltonian Cycle | Backtracking-6
- Number of Hamiltonian cycle
- Degree of a Cycle Graph
Improved By : PranchalK