
Last chance! 50% off unlimited learning
Sale ends in
Dominator tree of a directed graph.
dominator_tree(graph, root, mode = c("out", "in"))
A directed graph. If it is not a flowgraph, and it contains some vertices not reachable from the root vertex, then these vertices will be collected and returned as part of the result.
The id of the root (or source) vertex, this will be the root of the tree.
Constant, must be ‘in
’ or ‘out
’. If
it is ‘in
’, then all directions are considered as opposite to
the original one in the input graph.
A list with components:
A numeric vector giving the
immediate dominators for each vertex. For vertices that are unreachable from
the root, it contains NaN
. For the root vertex itself it contains
minus one.
A graph object, the dominator tree. Its vertex ids are the as the vertex ids of the input graph. Isolate vertices are the ones that are unreachable from the root.
A numeric vector containing the vertex ids that are unreachable from the root.
A flowgraph is a directed graph with a distinguished start (or root) vertex
This function implements the Lengauer-Tarjan algorithm to construct the dominator tree of a directed graph. For details see the reference below.
Thomas Lengauer, Robert Endre Tarjan: A fast algorithm for finding dominators in a flowgraph, ACM Transactions on Programming Languages and Systems (TOPLAS) I/1, 121--141, 1979.
# NOT RUN {
## The example from the paper
g <- graph_from_literal(R-+A:B:C, A-+D, B-+A:D:E, C-+F:G, D-+L,
E-+H, F-+I, G-+I:J, H-+E:K, I-+K, J-+I,
K-+I:R, L-+H)
dtree <- dominator_tree(g, root="R")
layout <- layout_as_tree(dtree$domtree, root="R")
layout[,2] <- -layout[,2]
plot(dtree$domtree, layout=layout, vertex.label=V(dtree$domtree)$name)
# }
Run the code above in your browser using DataLab