Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an edge is in some cycle?

Tags:

graph

cycle

I have a hw problem that asks for an algorithm that detects if there is any cycle in any undirected graph that contains any given edge 'E'. The algorithm should run in O(N) linear time.

The problem I have is that I don't know where to start. I have some simple sample graphs but I dont know where to go from there.

Any hints?

like image 273
calccrypto Avatar asked Oct 11 '11 23:10

calccrypto


People also ask

How do you determine if an edge is part of a cycle?

Cycle detection The existence of a cycle in directed and undirected graphs can be determined by whether depth-first search (DFS) finds an edge that points to an ancestor of the current vertex (it contains a back edge). All the back edges which DFS skips over are part of cycles.

How do you check if there is a cycle in graph?

There is a cycle in a graph only if there is a back edge present in the graph. Depth First Traversal can be used to detect a cycle in a Graph, DFS for a connected graph produces a tree.

Can an edge be a part of more than one cycle?

An undirected graph can contain an edge which belongs to all of its cycles graph only if this graph has a single cycle. Let's look at an example. Edge (2,3) belongs to two cycles, but you always can find a third cycle to which such an edge doesn't belong.

Can DFS detect cycles?

Use DFS from every unvisited node. Depth First Traversal can be used to detect a cycle in a Graph.


1 Answers

Take out that edge (u,v) from G. 1. Run BFS to see if v is still reachable from u. 2. if yes, then the original graph has a cycle containing e. otherwise there is not.

like image 153
urashima9616 Avatar answered Sep 18 '22 18:09

urashima9616