tags:

views:

76

answers:

1

What would the following algorithm look like:

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

I have following Idea:

for each v that belongs to V, if v is a descendant of e and (e,v) has not been traversed then check following:

if we visited e before v and left v before we left e then the graph contains cycle

A: 

I am not sure if this is your homework so I'll just give a little hint - use the properties of breadth-first search tree (with root in any of the two vertices of the edge e), its subtrees which are determined by neighbors of the root and the edges between those subtrees.

dark_charlie