简体   繁体   中英

Inconsistency in determining directed graph's back edges via DFS

I have found multiple algorithms that allows determining the back edges of a directed graph using DFS. Unfortunately, I found an inconsistency in one of the graphs I am analyzing. Please find below a minimal example:

在此处输入图像描述

For this directed graph, I expected the algorithms to determine only one back edge that is the one I marked in red: E->B .

Instead, differently from my understanding, the algorithms can determine as a back edge also edge B->E . The different results depend on the graph's traversals, for instance:

Traversal     | Back Edge
-------------------------
A->B->D->E    | E->B
A->C->D->E->B | B->E

Q1: Is it correct assuming that the graph's back edge is only E->B ?

Q2: If so, which algorithm can guarantee the correct DFS traversal?

Answer to Q1: No. As the back edges are dependant on the DFS tree.

Definition of back edge: Given a DFS tree of a graph, a back edge is an edge from a node to one of its ancestors in the DFS tree. In other words, a back edge is an edge that connects a vertex to a vertex that has been visited before it's parent.

There can be multiple DFS trees possible based on the order of nodes in adjacency list or the order in which you decide to visit the nodes.

Therefore, for a particular DFS tree -> Unique set of back edges .

Answer to Q2: As discussed, there is no kind of correct DFS traversal. Multiple DFS traversal can exist for a same tree or graph.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM