has_eulerian_path#
- has_eulerian_path(G, source=None)[source]#
Return True iff
Ghas an Eulerian path.An Eulerian path is a path in a graph which uses each edge of a graph exactly once. If
sourceis specified, then this function checks whether an Eulerian path that starts at nodesourceexists.- A directed graph has an Eulerian path iff:
at most one vertex has out_degree - in_degree = 1,
at most one vertex has in_degree - out_degree = 1,
every other vertex has equal in_degree and out_degree,
and all of its vertices belong to a single connected component of the underlying undirected graph.
If
sourceis not None, an Eulerian path starting atsourceexists if no other node has out_degree - in_degree = 1. This is equivalent to either there exists an Eulerian circuit orsourcehas out_degree - in_degree = 1 and the conditions above hold.- An undirected graph has an Eulerian path iff:
exactly zero or two vertices have odd degree,
and all of its vertices belong to a single connected component.
If
sourceis not None, an Eulerian path starting atsourceexists if either there exists an Eulerian circuit orsourcehas an odd degree and the conditions above hold.Graphs with isolated vertices (i.e. vertices with zero degree) are not considered to have an Eulerian path. Therefore, if the graph is not connected (or not strongly connected, for directed graphs), this function returns False.
- Parameters
- GNetworkX Graph
The graph to find an euler path in.
- sourcenode, optional
Starting node for path.
- Returns
- BoolTrue if G has an Eulerian path.
See also