Skip to main content
`Ctrl`+`K`

# lowest_common_ancestor

lowest_common_ancestor(G, node1, node2, default=None)

  Compute the lowest common ancestor of the given pair of nodes.

  Parameters:
    G NetworkX directed graph
    node1, node2 nodes in the graph.
    default object

      Returned if no common ancestor between `node1` and `node2`

  Returns:
    The lowest common ancestor of node1 and node2,
    or default if they have no common ancestors.

  See also

  `all_pairs_lowest_common_ancestor`

  Examples

      >>> G = nx.DiGraph()
      >>> nx.add_path(G, (0, 1, 2, 3))
      >>> nx.add_path(G, (0, 4, 3))
      >>> nx.lowest_common_ancestor(G, 2, 4)
      0