# Preferring forward edges to cross edges during graph DFS traversal

It's well known that depth-first search order of a graph is (usually) not unique, and multiple orders are possible depending on the order in which successors are processed for each node. Let's consider rooted directed graphs in the following discussion.

Muchnick 1997 gives an example: .

Intuitively, DFS with (more) forward edges is "better"/"more useful" than one with (more) cross edges. Is there a methodology/algorithm for ordering successor selection to construct such DFS spanning trees (like (b) in the example above)? (Of course, an algorithm better than generating all possible DFS trees in exponential time and then selecting "the best".)

• Do you imply a directed acyclic graph? "Intuitively, DFS with (more) forward edges is 'better'/'more useful' than one with (more) cross edges". Although I would agree intuitively, can you actually explain why? – John L. Nov 12 '18 at 23:46
• "Do you imply a directed acyclic graph?" - No, as the question says, "a graph", which is hopefully good enough rendition of "an arbitrary graph" is English ;-). – pfalcon Nov 13 '18 at 4:03
• "Although I would agree intuitively, can you actually explain why?" Well, e.g. when graph represents a CFG (control flow graph) in the program analysis. The graph on the left could represent if (a and b) then D else Cconstruct. The DFS tree in the middle, with forward edge, arguably "preserves" "shape" of this meaning, while one with cross edge arguably "obfuscates". – pfalcon Nov 13 '18 at 4:13
• Thanks for the clarification about direct acyclic graph. I guess you mean an undirected graph even if all graphs in your question are directed acyclic graph. By the way, how far have you tried in constructing a wanted algorithm? – John L. Nov 13 '18 at 7:30
• On your explanation about the advantage of graph (b), you mentioned if (a and b) then D else C. However, a and b are symmetric in that snippet while A and B in graph (a) are not. – John L. Nov 13 '18 at 7:34