Given positive weighted undirected graph, find minimum weight cycle in it.
The idea is to use shortest path algorithm. We one by one remove every edge from graph, then we find shortest path between two corner vertices of it. We add an edge back before we process next edge.
1). create an empty vector 'edge' of size 'E' ( E total number of edge). Every element of this vector is used to store information of all the edge in graph info 2) Traverse every edge edge[i] one - by - one a). First remove 'edge[i]' from graph 'G' b). get current edge vertices which we just removed from graph c). Find the shortest path between them "Using Dijkstra’s shortest path algorithm " d). To make a cycle we add weight of the removed edge to the shortest path. e). update min_weight_cycle if needed 3). return minimum weighted cycle
Below c++ implementation of above idea
Time Complexity : O( E ( E log V ) )
For every edge we run dijkstra’s shortest path algorithm so over all time complexity E2logV.
In set 2 | we will discuss optimize algorithm to find minimum weight cycle in undirected graph.
This article is contributed by Nishant Singh . 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.
- Check if there is a cycle with odd weight sum in an undirected graph
- Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)
- Detect cycle in an undirected graph
- Detect cycle in an undirected graph using BFS
- Number of single cycle components in an undirected graph
- Karp's minimum mean (or average) weight cycle algorithm
- Sum of the minimum elements in all connected components of an undirected graph
- Find k-cores of an undirected graph
- Find if an undirected graph contains an independent set of a given size
- Program to find Circuit Rank of an Undirected Graph
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Find the weight of the minimum spanning tree
- Detect cycle in the graph using degrees of nodes of graph
- 0-1 BFS (Shortest Path in a Binary Weight Graph)
- Clone an Undirected Graph