networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
tree_all_pairs_lowest_common_ancestor(G, root=None, pairs=None)

Notes

Only defined on non-null trees represented with directed edges from parents to children. Uses Tarjan's off-line lowest-common-ancestors algorithm. Runs in time $O(4 \times (V + E + P))$ time, where 4 is the largest value of the inverse Ackermann function likely to ever come up in actual use, and $P$ is the number of pairs requested (or $V^2$ if all are needed).

Tarjan, R. E. (1979), "Applications of path compression on balanced trees", Journal of the ACM 26 (4): 690-715, doi:10.1145/322154.322161.

Parameters

G : NetworkX directed graph (must be a tree)
root : node, optional (default: None)

The root of the subtree to operate on. If None, assume the entire graph has exactly one source and use that.

pairs : iterable or iterator of pairs of nodes, optional (default: None)

The pairs of interest. If None, Defaults to all pairs of nodes under :None:None:`root` that have a lowest common ancestor.

Returns

lcas : generator of tuples `((u, v), lca)` where `u` and `v` are nodes

in pairs and :None:None:`lca` is their lowest common ancestor.

Yield the lowest common ancestor for sets of pairs in a tree.

See Also

all_pairs_lowest_common_ancestor

similar routine for general DAGs

lowest_common_ancestor

just a single pair for general DAGs

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.lowest_common_ancestors.all_pairs_lowest_common_ancestor networkx.algorithms.lowest_common_ancestors.lowest_common_ancestor

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/lowest_common_ancestors.py#16
type: <class 'function'>
Commit: