Find cheapest cycle in an undirected weighted graph - algorithm

I'm stuck on searching an algorithm to find the cheapest cycle in a weighted undirected graph in O(n^2). The cycle does not have to visit every vertex in the graph (i.e. I'm not looking for a Hamiltonian cycle).
Can someone help me finding a strategy?
an example of weighted undirected graph:

I'm not sure where the O(n^2) time bound came from. The obvious O(n (m + n log n))-time algorithm is, for each vertex, to compute a shortest-path tree from that vertex and then consider the fundamental cycle made by a non-tree edge and some tree edges.

Related

DFS on undirected graph complexity?

As when we traverse the undirected connected graph using DFS and mark out only edges which we travel during DFS, we end up with a DFS tree which is basically a tree and traversing a tree requires O(v) complexity where v is the number of vertices, then why it stated that complexity is O(v + e)?
I know it's a noob question but I am confused.
The DFS tree is the tree made of the edges you traversed. You indeed only traverse O(V) edges. But in order to traverse an edge, you first examine the edge to check if it will lead to a vertex you already encountered. This means you examine more edges than you traverse. Indeed, you examine O(E) edges. So the total work is O(V+E).
Note: Because your graph is connected, you are sure that E > V. In that case the complexity can be rewritten O(E).
you find all the nodes of graph through edges so the time complexity depends upon no. of edges as well that's why the O(e) is also included. If you consider complete graph TC will be O(V^2).
Consider two different graphs:
A graph having more edges than vertices, for instance a connected graph with a high minimum degree.
When the DFS algorithm visits a vertex, it will have to follow each of the edges that connect this vertex, repeating a DFS traversal from the neighboring vertices. Of course, if that neighbor was already visited, the DFS algorithm will backtrack, but at least we can state that the edge had to be processed.
This procedure will process all edges of the graph. So in this case we can say the algorithm is O(e)
A graph having fewer edges than vertices, often a disconnected graph (in the extreme case there are no edges).
When the DFS algorithm has visited all vertices that it can reach from a traversal that started in vertex A, it must still iterate over the remaining vertices, to find vertices that might not have been visited. These unvisted vertices do not belong to the same connected component). Another DFS traversal must start from there.
This way all vertices are processed. So in this case the algorithm has a O(v) time complexity
So in general, the algorithm has a O(max(e, v)) time complexity. You could also say that the algorithm must visit all edges and all vertices, and so the algorithm has a O(e+v) time complexity. Both are equivalent.

Are Prim's and Kruskal's Algorithm, shortest path algorithms?

Can these algorithms come under Dijkshtra's , Bellman-Ford , BFS, DFS algorithms?
I think no, and this is why;
Prim's and Kruskal's algorithms solve the Minimum Spanning Tree problem, and MST problem is different than Shortest Path problem.
What is the difference between them?:
MST: requirement is to reach each vertex once (create graph tree) and total (collective) cost of reaching each vertex is required to be minimum among all possible combinations.
SP: requirement is to reach destination vertex from source vertex with lowest possible cost (shortest weight). So here we do not worry about reaching each vertex instead only focus on source and destination vertices and thats where lies the difference.

Present a greedy algorithm to find a longest cycle in an unweighted graph

I could only think of a trivial solution to find all cycles in the graph and then find the number of edges in each cycle and then return the one with maximum edges.
How do I find a longest cycle using a greedy algorithm?
"The longest simple cycle problem is the problem of
finding a cycle of maximum length in a graph. As a
generalization of the Hamiltonian cycle problem, it is NPcomplete on general graphs and, in fact, on every class of graphs
that the Hamiltonian cycle problem is NP-complete. The longest
simple cycle problem may be solved in polynomial time on
the complements of comparability graphs. It may also be solved
in polynomial time on any class of graphs with bounded tree
width or bounded clique-width, such as the distance-hereditary
graphs. However, it is NP-hard even when restricted to split
graphs, circle graphs, or planar graphs. In this paper a heuristic
algorithm is proposed which can solve the problem in polynomial
time. To solve the longest simple cycle problem using adjacency
matrix and adjacency list by making a tree of given problem to
find the longest simple cycle as the deepest path in tree following
reconnect the leaf node of deepest path with root node. The result
resolves the open question for the complexity of the problem on
simple unweighted graphs. The algorithm is implemented on a
simple labeled graph without parallel edges and without selfloop. The worst case time complexity for the proposed algorithm
is O(V+E).
The Longest Simple Cycle Algorithm
In the Proposed Algorithm, the input graph considered to be a
simple graph (i.e. without self-loop and without parallel
edges), the algorithm for Longest Simple Cycle in simple
graph is summarized below:
Enumerate all the nodes to calculate degree of each node to
find the node with highest degree.
Assign the node with highest degree as the root for tree.
Construct a tree T of the given graph G considering the
adjacent nodes as successor and predecessors accordingly
for each vertex using adjacency matrix.
Do apply the proposed LSC algorithm to find the longest
path.
Join the leaf node of the longest path with root and retrieve
the path considering it as the longest cycle in graph."
A Heuristic Algorithm for Longest Simple Cycle Problem

Find the lowest-weight cycle in a weighted, directed graph using Dijkstra's

Hi I am struggling with this question. It is the following:
Devise an algorithm to find the lowest-weight cycle(i.e. of all cycles in the graph, the one with the smallest sum of edge weights), in a weighted, directed graph G = (V,E). Briefly justify the runtime and space complexity. Assume all edges are non-negative. It should run in O(|V||E|log|V|) time.
Hint: Use multiple calls to Dijkstra's algorithm.
I have seen solutions that use Floyd-Warshall but I was wondering how we would do this using Dijkstra's and how to do it within the time constraint given.
I have a few points of confusion:
Firstly, how do we even know how many cycles are in the graph and how
to check those?
Also, why is it |E||V|log|V|? By my understanding you should traverse
through all the vertices therefore making it |V|log|V|.
This is for my personal learning so if anyone has an example they could use, it would greatly help me! I am not really looking for pseudo-code - just a general algorithm to understand how using the shortest path from one node to all nodes is going to help us solve this problem.
Thank you!
Call Dijkstra's algorithm from each vertex to find the shortest path to itself, if one exists. The shortest path from any vertex to itself is the smallest cycle.
Dijkstra's algorithm takes O(|E| log |V|), so total time is O(|V||E| log |V|).
Note that this time can be worse than Floyd-Warshall, because there can be O(|V|^2) edges in the graph.
Call Dijkstra's algorithm |V| times, using each vertex in V as the start vertex. Store the results in a matrix, where dist(u,v) is the shortest path length from u to v.
For each pair of vertices (u,v), dist(u,v) is the shortest parth from u to v and dist(v,u) is the shortest path from v to u. Therefore, dist(u,v) + dist(v, u) is the length of the lowest weight cycle containing u and v. For each pair of vertices, computer this value and take the minimum. This is the lowest weigtht cycle.

Find a minimum weighted spanning tree of the Cycle graph

I'm trying to solve the problem presented above and here is my attempt:
Attempt: We can apply Dijkstra's shortest path algorithm instead of using Prim's and Kruskal's algorithms to find a MST as Dijkstra will visit all the nodes in the smallest weighted distance. Complexity: For G = (V,E), O(E log(V))
Questions:
(1) Is my approach correct ?
(2) Is it the most efficient answer to the question ?
If i'm completely wrong, I would appreciate a correct and efficient solution.
A cycle graph contains no edges other than those connecting the vertices in the cycle. So what we can do is iterate through all N edges and eliminate the maximum weighted edge forming a spanning tree of N - 1 edges containing the minimum sum of edges, forming a Minimum Spanning Tree.

Resources