Lengauer-Tarjan algorithm
A path
We compute sdom[*] using the reverse pre-order to
utilize already-computed sdom[*] of larger indices. For
each vertex v, enumerate its predecessor u,
and the minimum pre-order number in the ancestor path of u
provides a candidate sdom[v]. The following implementation
employs a trick by merging parent[] into
uf[].
With a simple implementation of eval-link, the time complexity is
1 |
|
With a sophisticated method balancing union-find trees, the time
complexity can be improved to
Semi-NCA algorithm
Loukas Georgiadis proposed the Semi-NCA algorithm in Linear-Time
Algorithms for Dominators and Related Problems. It has a time
complexity of
For each vertex v that is not the source,
idom(v) is the lowest common ancestor of
sdom(v) and parent(v). For each vertex
v in the pre-order except the source, ascend the ancestor
path of v and find the deepest vertex whose pre-order
number is less than or equal to sdom(v)'s number.
1 |
|
Testdata
The following tests helped me diagnose bugs in my semi-NCA implementation.
1 | digraph { |
1 | digraph { |
1 | digraph { |
Iterative DFS
1 |
|
Dynamic dominators
Depth Based Search
After insertion of (x,y), v is affected iff depth(nca)+1 < depth(v) && exists path P from y to v s.t depth(v) <= depth(w) and d(v) is changed to nca
Natural loops
See natural loops.