Question

In: Advanced Math

Design a linear-time algorithm which, given an undirected graph G and a particular edge e in...

Design a linear-time algorithm which, given an undirected graph G and a particular edge e in it, determines whether G has a cycle containing e. Your algorithm should also return the length (number of edges) of the shortest cycle containing e, if one exists. Just give the algorithm, no proofs are necessary. Hint: you can use BFS to solve this.

Solutions

Expert Solution

SOLUTION:

FROM THE GIVEN PROBLEM

This can be reduced to Shortest Path Problem:

Find the shortest path from v to u, then the shortest cycle that contains (u,v), is v->...->u->v, where v->...->u is the shortest path from v to u as found by the shortest path algorithm.

It can be solved efficiently using Dijkstra's Algorithm, since there are no negative weights in the graph.

Correctness Proof:

Assume there is a cheaper cycle v1->v2->...vi->u->v->v_i+1->...->vn->v1. Let's say it weights x < d(v,u) + w(u,v)
Since it's a cycle, we can look at it as v->v_i+1->....->vn->v1->...->vi->u->v.
The weight of the cycle didn't change, and is still x. This means x=w(v,v_i+1) + ... + w(vn,v1) + ... + w(v_i-1,vi) + w(vi,u) + w(u,v)
But this gives us w(v,v_i+1) + ... + w(vn,v1) + ... + w(v_i-1,vi) + w(vi,u) + w(u,v) - w(u,v) < d(v,u), and we have found a shorter path from v to u, than d(v,u), which is contradicting correctness of Dijkstra's Algorithm.


Related Solutions

You are given an undirected graph G = ( V, E ) in which the edge...
You are given an undirected graph G = ( V, E ) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight from 1 to W, where W is a constant (independent of the number of edges or vertices). Show that it is possible to compute the single-source shortest paths in such a graph in O(E+V) time.
Given an undirected graph G=(V, E) with weights and a vertex , we ask for a...
Given an undirected graph G=(V, E) with weights and a vertex , we ask for a minimum weight spanning tree in G where is not a leaf (a leaf node has degree one). Can you solve this problem in polynomial time? Please write the proof.
Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph...
Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph contains a cycle, then your algorithm should output one. (It should not output all cycles in the graph, just one of them.) The running time of your algorithm should be O(m + n) for a graph with n nodes and m edges.
Given an undirected graph G = (V,E), consisting of n vertices and m edges, with each...
Given an undirected graph G = (V,E), consisting of n vertices and m edges, with each edge labeled from the set {0,1}. Describe and analyze the worst-case time complexity of an efficient algorithm to find any cycle consisting of edges whose labels alternate 0,1.
Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈...
Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈ V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v). (a) Design an algorithm that returns a list containing the neighbourhood degree for each node v ∈...
Give an algorithm that constructs an undirected connected graph, which allows for labeling of the n...
Give an algorithm that constructs an undirected connected graph, which allows for labeling of the n vertices u - v <= k for every edge (u,v), where k is some constant. All nodes have a unique label.
Prove or disprove: If G = (V; E) is an undirected graph where every vertex has...
Prove or disprove: If G = (V; E) is an undirected graph where every vertex has degree at least 4 and u is in V , then there are at least 64 distinct paths in G that start at u.
Suppose G is a connected cubic graph (regular of degree 3) and e is an edge...
Suppose G is a connected cubic graph (regular of degree 3) and e is an edge such that G − e has two connected components G1 and G2 (a) Explain what connected means. (b) We say that e is a____________ of G (c) show that G1 has an odd number of vertices. (d) draw a connected cubic graph G with an edge e as above.
5. Suppose we are given both an undirected graph G with weighted edges and a minimum...
5. Suppose we are given both an undirected graph G with weighted edges and a minimum spanning tree T of G . (a) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is decreased. (b) Describe an algorithm to update the minimum spanning tree when the weight of a single edge e is increased. In both cases, the input to your algorithm is the edge e and its new weight; your algorithms...
(1) Run Prim's algorithm and Kruskal's algorithm for the following graph: G(V, E) where V =...
(1) Run Prim's algorithm and Kruskal's algorithm for the following graph: G(V, E) where V = {A, B, C, D, E} E = { {A,B}, {B,C}, {C, A}. {B, D}, {B, E}, {D, E}} use edge weights: w({A, B} = 1), w({B, C}) = 2, w({C, A}) = 3, w({B, D}) = 4, w({B, E}) = 5, w({D, E}) = 6. (2) Can the maximum weight edge be in every minimum spanning tree of a graph?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT