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 firstname.lastname@example.org. 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
- Product of minimum edge weight between all pairs of a Tree
- Remove all outgoing edges except edge with minimum weight
- Karger's algorithm for Minimum Cut | Set 1 (Introduction and Implementation)
- Boruvka's algorithm for Minimum Spanning Tree
- Karger’s algorithm for Minimum Cut | Set 2 (Analysis and Applications)
- Reverse Delete Algorithm for Minimum Spanning Tree
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- Count the nodes in the given tree whose weight is even
- Count the nodes in the given tree whose sum of digits of weight is odd
- 0-1 BFS (Shortest Path in a Binary Weight Graph)
- Count the nodes in the given tree whose weight is prime
- Count the nodes whose weight is a perfect square
Improved By : PranchalKatiyar