In graph theory, a path in a graph is a finite or infinite sequence of edges which connect a sequence of vertices which, by most definitions, are all distinct from one another. In a directed graph, a directed path (sometimes called dipath[1]) is again a sequence of edges (or arcs) which connect a sequence of vertices, but with the added restriction that the edges all be directed in the same direction.

Contents

A path is a trail in which all vertices (except possibly the first and last) are distinct.
A trail is a walk in which all edges are distinct.
A walk of length k{\displaystyle k} in a graph is an alternating sequence of vertices and edges, v0,e0,v1,e1,v2,…,vk−1,ek−1,vk{\displaystyle v_{0},e_{0},v_{1},e_{1},v_{2},\ldots ,v_{k-1},e_{k-1},v_{k}}, which begins and ends with vertices. If the graph is undirected, then the endpoints of ei{\displaystyle e_{i}} are vi{\displaystyle v_{i}} and vi+1{\displaystyle v_{i+1}}. If the graph is directed, then ei{\displaystyle e_{i}} is an arc from vi{\displaystyle v_{i}} to vi+1{\displaystyle v_{i+1}}. An infinite path is an alternating sequence of the same type described here, but with no first or last vertex, and a semi-infinite path (also ray) has a first vertex, v0{\displaystyle v_{0}}, but no last vertex. Most authors require that all of the edges and vertices be distinct from one another. However, some authors do not make this requirement, and instead use the term simple path to refer to a path which contains no repeated vertices.

A weighted graph associates a value (weight) with every edge in the graph. The weight of a path in a weighted graph is the sum of the weights of the traversed edges. Sometimes the words cost or length are used instead of weight.

Two paths are vertex-independent (alternatively, internally vertex-disjoint) if they do not have any internal vertex in common. Similarly, two paths are edge-independent (or edge-disjoint) 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 distance between two vertices in a graph is the length of a shortest path between them, if one exists, and otherwise the distance is infinity.

The diameter of a connected graph is the largest distance (defined above) between pairs of vertices of the graph.

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 (or no 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.