In graph theory, a path in a graph is a finite or infinite sequence of edges which joins a sequence of vertices which, by most definitions, are all distinct. A directed path in a directed graph is a finite or infinite sequence of edges which joins a sequence of distinct vertices, but with the added restriction that the edges be all directed in the same direction. Paths are fundamental concepts of graph theory, described in the introductory sections of most graph theory texts. See e.g. Bondy and Murty, Gibbons, or Diestel. Korte et al. cover more advanced algorithmic topics concerning paths in graphs.
Definitions
Walk, trail, path
A walk is a finite or infinite sequence of edges which joins a sequence of vertices.
A trail is a walk in which all edges are distinct.
A path is a trail in which all vertices are distinct.
If is a finite walk with vertex sequence then w is said to be a walk fromv1tovn. Similarly for a trail or a path. If there is a finite walk between two distinct vertices then there is also a finite trail and a finite path between them. Some authors do not require that all vertices of a path be distinct and instead use the term simple path to refer to such a path. A weighted graph associates a value with every edge in the graph. The weight of a walk in a weighted graph is the sum of the weights of the traversed edges. Sometimes the wordscost or length are used instead of weight.
Directed walk, trail, path
A directed walk is a finite or infinite sequence of edges directed in the same direction which joins a sequence of vertices.
A directed trail is a directed walk in which all edges are distinct.
A directed path is a directed trail in which all vertices are distinct.
If is a finite directed walk with vertex sequence then w is said to be a walk fromv1tovn. Similarly for a directed trail or a path. If there is a finite directed walk between two distinct vertices then there is also a finite directed trail and a finite directed path between them. Some authors do not require that all vertices of a directed path be distinct and instead use the term simple directed path to refer to such a directed path. A weighted directed graph associates a value with every edge in the directed graph. The weight of a directed walk in a weighted directed graph is the sum of the weights of the traversed edges. Sometimes the words cost or length are used instead of weight.
Examples
A graph is connected if there are paths containing each pair of vertices.
A directed graph is strongly connected if there are oppositely oriented directed paths containing each pair of vertices.
A path such that no graph edges connect two nonconsecutive path vertices is called an induced path.
A path that includes every vertex of the graph is known as a Hamiltonian path.
Two paths are vertex-independent if they do not have any internal vertex in common. Similarly, two paths are edge-independent if they do not have any internal edge in common. Two internally vertex-disjoint paths are edge-disjoint, but the converse is not necessarily true.
The diameter of a connected graph is the largest distance between pairs of vertices of the graph.
Finding paths
Several algorithms exist to find shortest and longest paths in graphs, with the important distinction that the former problem is computationally much easier than the latter. Dijkstra's algorithm produces a list of shortest paths from a source vertex to every other vertex in directed and undirected graphs with non-negative edge weights, whilst the Bellman–Ford algorithm can be applied to directed graphs with negative edge weights. The Floyd–Warshall algorithm can be used to find the shortest paths between all pairs of vertices in weighted directed graphs.