Java Program to Find a Good Feedback Edge Set in a Graph

• Last Updated : 15 Oct, 2021

Feedback edge set is a set of edges where F âŠ† E of a directed graph G, whose every cycle must contain at least one edge from F.

In simple words, Feedback edge set is a set of edges whose removal from the graph makes the graph directed acyclic graph.

Examples:

Input:

Output:

Feedback Edge Set: ( 3 -> 1 ) ( 4 -> 3 )

Explanation:

Clearly two edges 3 -> 1 and 4 -> 3 will make the graph acyclic.

Approach:

A feedback edge set can be find out with simple BFS but if the given graph is a DAG then there have to be no edge set.

1. Check if the given graph is already a directed acyclic graph and remove all the sink vertex.
2. Return the modified graph and run BFS.
3. Mark the visited vertices while running BFS.
4. If marked vertex is visited once again, then print out that edge as feedback edge.

Code:

Java

Output

Feedback Edge Set: ( 3 -> 1 ) ( 4 -> 3 )

Time Complexity: O(E*V) where E is the number of edges and V is the number of vertices.

My Personal Notes arrow_drop_up