Recent from talks
Nothing was collected or created yet.
Path (graph theory)
View on Wikipedia
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 (and since the vertices are distinct, so are the edges). A directed path (sometimes called dipath[1]) 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 & Murty (1976), Gibbons (1985), or Diestel (2005). Korte et al. (1990) cover more advanced algorithmic topics concerning paths in graphs.
Definitions
[edit]Walk, trail, and path
[edit]
- Let G = (V, E, Φ) be a graph. A finite walk is a sequence of edges (e1, e2, ..., en − 1) for which there is a sequence of vertices (v1, v2, ..., vn) such that Φ(ei) = {vi, vi + 1} for i = 1, 2, ..., n − 1. (v1, v2, ..., vn) is the vertex sequence of the walk. The walk is closed if v1 = vn, and it is open otherwise. An infinite walk is a sequence of edges of the same type described here, but with no first or last vertex, and a semi-infinite walk (or ray) has a first vertex but no last vertex.
- A trail is a walk in which all edges are distinct.[2]
- A path is a trail in which all vertices (and therefore also all edges) are distinct.[2]
If w = (e1, e2, ..., en − 1) is a finite walk with vertex sequence (v1, v2, ..., vn) then w is said to be a walk from v1 to vn. 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 where all vertices are distinct.
A weighted graph associates a value (weight) with every edge in the graph. The weight of a walk (or trail or 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.
Directed walk, directed trail, and directed path
[edit]- A directed walk is a finite or infinite sequence of edges directed in the same direction which joins a sequence of vertices.[2]
- Let G = (V, E, Φ) be a directed graph. A finite directed walk is a sequence of edges (e1, e2, ..., en − 1) for which there is a sequence of vertices (v1, v2, ..., vn) such that Φ(ei) = (vi, vi + 1) for i = 1, 2, ..., n − 1. (v1, v2, ..., vn) is the vertex sequence of the directed walk. The directed walk is closed if v1 = vn, and it is open otherwise. An infinite directed walk is a sequence of edges of the same type described here, but with no first or last vertex, and a semi-infinite directed walk (or ray) has a first vertex but no last vertex.
- A directed trail is a directed walk in which all edges are distinct.[2]
- A directed path is a directed trail in which all vertices are distinct.[2]
If w = (e1, e2, ..., en − 1) is a finite directed walk with vertex sequence (v1, v2, ..., vn) then w is said to be a walk from v1 to vn. 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.
A "simple directed path" is a path where all vertices are distinct.
A weighted directed graph associates a value (weight) with every edge in the directed graph. The weight of a directed walk (or trail or path) 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
[edit]- 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 without repeats is known as a Hamiltonian path.
- Two paths are vertex-independent (alternatively, internally disjoint or internally vertex-disjoint) if they do not have any internal vertex or edge in common. Similarly, two paths are edge-independent (or edge-disjoint) if they do not have any edge in common. Two internally 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.
Finding paths
[edit]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.
The path partition problem
[edit]The k-path partition problem is the problem of partitioning a given graph to a smallest collection of vertex-disjoint paths of length at most k.[3]
See also
[edit]Notes
[edit]- ^ McCuaig 1992, p. 205.
- ^ a b c d e f Bender & Williamson 2010, p. 162.
- ^ Chen, Yong; Goebel, Randy; Lin, Guohui; Su, Bing; Xu, Yao; Zhang, An (2019-07-01). "An improved approximation algorithm for the minimum 3-path partition problem". Journal of Combinatorial Optimization. 38 (1): 150–164. doi:10.1007/s10878-018-00372-z. ISSN 1382-6905.
References
[edit]- Bender, Edward A.; Williamson, S. Gill (2010). Lists, Decisions and Graphs. With an Introduction to Probability.
- Bondy, J. A.; Murty, U. S. R. (1976). Graph Theory with Applications. North Holland. p. 12-21. ISBN 0-444-19451-7.
- Diestel, Reinhard (2005). Graph Theory. Springer-Verlag. pp. 6–9. ISBN 3-540-26182-6.
- Gibbons, A. (1985). Algorithmic Graph Theory. Cambridge University Press. pp. 5–6. ISBN 0-521-28881-9.
- Korte, Bernhard; Lovász, László; Prömel, Hans Jürgen; Schrijver, Alexander (1990). Paths, Flows, and VLSI-Layout. Springer-Verlag. ISBN 0-387-52685-4.
- McCuaig, William (1992). "Intercyclic Digraphs". In Robertson, Neil; Seymour, Paul (eds.). Graph Structure Theory. AMS–IMS–SIAM Joint Summer Research Conference on Graph Minors, Seattle, June 22 – July 5, 1991. American Mathematical Society. p. 205.
Path (graph theory)
View on GrokipediaDefinitions
Walks, Trails, and Paths
In graph theory, a walk in an undirected graph is formally defined as an alternating sequence of vertices and edges , where each , each , and is incident to and for .[6] Walks permit repetitions of both vertices and edges, allowing arbitrary traversal through the graph.[7] A trail is a walk in which no edge is repeated.[6] Thus, trails may revisit vertices but must use each edge at most once, providing a structure that avoids redundant edge usage while potentially looping back through shared vertices.[7] A path is a trail in which no vertex is repeated, except possibly the initial and terminal vertices in the case of closed variants.[6] For open paths, all vertices are distinct, ensuring a simple progression from start to end without revisiting any vertex.[7] The length of a walk, trail, or path is the number of edges in the sequence, so a path of length consists of edges and distinct vertices.[6] Walks, trails, and paths form a hierarchy: every path is a trail, and every trail is a walk, with increasing restrictions on repetitions.[7] A walk, trail, or path is closed if its initial vertex equals its terminal vertex (); a closed path (with no other repeated vertices) is known as a cycle.[6]Directed Variants
In directed graphs, also known as digraphs, the concepts of walks, trails, and paths are adapted to respect the orientation of edges, which are directed from an initial vertex to a terminal vertex. A directed walk is a sequence of vertices and directed edges such that each edge is directed from to for .[8] This allows repetitions of both vertices and edges, provided the direction is followed. A directed trail is a directed walk in which no directed edge is repeated.[8] Thus, while vertices may repeat, each arc appears at most once in the sequence. A directed path is a directed trail in which no vertex is repeated (except possibly the start and end in closed cases).[8] Directed paths are denoted as a path, indicating a sequence from vertex to vertex that follows the edge orientations without revisiting intermediate vertices.[8] In directed graphs, the existence of a directed path from to defines reachability, meaning can be accessed from by following the prescribed directions.[8] A closed directed path, known as a directed cycle, is a directed trail where the initial and terminal vertices coincide, with no other vertex repetitions.[8] This structure must traverse arcs in their oriented direction, distinguishing it from undirected counterparts by enforcing one-way traversal.Properties
Length and Simplicity
In graph theory, the length of a path is defined as the number of edges it contains in unweighted graphs.[9] In weighted graphs, the length is instead the sum of the weights assigned to those edges.[10] Formally, for a path , its length is given by , where denotes the set of edges in .[11] A simple path is a path that contains no repeated vertices, ensuring that all vertices in the sequence are distinct.[12] This property aligns with the standard definition of a path in many graph theory contexts, where paths are inherently simple to avoid redundancy.[13] The absence of repeated vertices in a simple path guarantees that it includes no cycles, distinguishing it from longer walks or trails that may revisit vertices or edges.[12] In connected undirected graphs, the existence of a simple path between any two vertices establishes that those vertices belong to the same connected component.[14] A geodesic path, or shortest simple path, between two vertices is one of minimal length among all simple paths connecting them, providing the fundamental measure of distance in the graph.[15]Cycles and Circuits
In graph theory, a cycle is defined as a closed path where no vertices are repeated except for the initial and final vertex, which coincide, and the cycle must include at least three distinct vertices to avoid trivial cases.[16] This ensures that the structure forms a loop without internal repetitions, distinguishing it from more general closed walks. In contrast, a circuit is a closed trail, meaning it is a sequence of edges forming a closed walk with no repeated edges, though vertices other than the start and end may be revisited.[16] The key difference lies in the allowance for vertex repetition in circuits, which permits more flexible traversals compared to the stricter no-repetition rule for vertices in cycles.[17] A graph is considered acyclic if it contains no cycles whatsoever, a property that characterizes forests in the undirected case, where a connected acyclic graph is specifically a tree.[18] This absence of cycles implies that any path between two vertices in such a graph is unique, providing a foundational structure for many algorithmic applications without looping redundancies.[19] Forests and trees thus serve as building blocks for understanding more complex graphs, where the introduction of even a single cycle alters connectivity and traversal properties fundamentally.[20] Cycles and circuits relate closely to open paths, as simple paths inherently avoid internal cycles by prohibiting vertex repetitions, ensuring a direct route without loops. In broader walks, the presence of a cycle can be detected and excised to produce a shorter walk connecting the same endpoints, a technique often used to simplify traversals toward finding minimal paths.[21] This process highlights how cycles represent detours in non-simple structures, allowing reduction to path-like efficiency without altering the overall connectivity.[22] Special cases of circuits include the Eulerian circuit, which is a closed trail that covers every edge in the graph exactly once, providing a complete traversal without edge reuse.[23] Similarly, a Hamiltonian cycle is a specific type of cycle that passes through every vertex in the graph exactly once before returning to the start, emphasizing vertex coverage over edge constraints.[24] These constructs extend the closed-path paradigm to global graph properties, influencing problems in connectivity and optimization.[25]Illustrations
Basic Examples
In graph theory, a fundamental illustration of a path is the path graph , which consists of vertices connected in a linear chain by edges, such as . This structure exemplifies a simple path where no vertex is repeated, and its diagram typically appears as a straight line of vertices with edges between consecutive ones; for instance, shows vertices 1-2-3-4 forming the path sequence 1-2-3-4.[26] To distinguish related concepts, consider a simple undirected graph forming a line with vertices labeled 1, 2, 3, 4 and edges between consecutive pairs (i.e., ). The sequence 1-2-3-4 is a path, as it visits each vertex exactly once without repeating edges. In contrast, the sequence 1-2-1-2 is a walk (allowing vertex and edge repetition) but not a trail, since it repeats the edge between 1 and 2.[17] Another basic example arises in the complete graph , a triangle with three vertices all pairwise connected by edges. Traversing the vertices in order, such as A-B-C-A, forms a cycle, which is a closed path that returns to the starting vertex without repeating any except the initial and final.[27] In directed graphs, paths follow edge orientations. A tournament graph, where every pair of distinct vertices has exactly one directed edge between them, always contains a directed Hamiltonian path visiting each vertex exactly once, such as from a source vertex (with out-degree ) to a sink (with in-degree ) in a simple transitive tournament like 1→2→3→4.[28] The Petersen graph, a 3-regular graph with 10 vertices often depicted as an outer pentagon, inner star, and connecting edges, serves as a key example lacking a Hamiltonian cycle (a closed path through all vertices), though it does possess Hamiltonian paths.[29]Graph-Specific Cases
In trees, which are connected acyclic graphs, there exists a unique path between any two distinct vertices, reflecting the absence of cycles that would otherwise permit alternative routes.[30] In complete graphs , where every pair of distinct vertices is connected by a single edge, the path between any two vertices is trivially of length 1 via the direct edge; moreover, for , Hamiltonian paths exist that visit each vertex exactly once, such as the sequence ordering all vertices linearly.[31] In bipartite graphs, with vertex set partitioned into two disjoint sets and such that all edges connect vertices between and , any path must alternate between the two partitions, starting in one and switching with each step; consequently, the length of the longest path (in terms of edges) is bounded by the partition sizes, at most , but more tightly limited to roughly twice the size of the smaller partition due to the alternation constraint.[32] For directed acyclic graphs (DAGs), a topological order provides a linear arrangement of vertices such that all directed edges point forward along the order, ensuring that any path respects this sequence without forming cycles and allowing paths to be identified as subsequences in the ordering.[33] In grid graphs, which form a lattice structure like an array of vertices connected horizontally and vertically, there are typically multiple shortest paths between opposite corners, such as from to , with the exact number given by the binomial coefficient , representing the ways to choose horizontal moves among the total steps.[34]Algorithms
Path Detection and Enumeration
Detecting the existence of a path between two vertices in a graph is a fundamental problem equivalent to determining reachability, where a vertex reaches if there exists a path from to .[35] In undirected graphs, this corresponds to checking if the vertices lie in the same connected component, which can be identified using traversal algorithms.[36] Depth-First Search (DFS) is a standard recursive algorithm for path existence, exploring as far as possible along each branch before backtracking on dead ends.[37] DFS starts from a source vertex and recursively visits adjacent unvisited vertices, marking them to avoid cycles, until it reaches the target or exhausts all possibilities.[37] The algorithm runs in time, linear in the graph size, making it efficient for sparse graphs.[37] To find an actual path, DFS can maintain a parent pointer or path stack during traversal.[37] For unweighted graphs, Breadth-First Search (BFS) detects the existence of a path while also guaranteeing the shortest one in terms of edge count, by exploring vertices level by level using a queue.[38] BFS, originally described for maze shortest paths, processes vertices in order of increasing distance from , ensuring the first encounter of yields the minimal-length path.[38] Like DFS, it operates in time.[38] Enumerating all simple paths—those without repeated vertices—between two vertices requires backtracking, an extension of DFS that systematically explores all possible extensions while pruning cycles by tracking visited vertices in the current path.[39] This approach builds paths incrementally, adding adjacent vertices and recursing until reaching the target or backtracking upon dead ends or cycles.[39] The time complexity is exponential, typically , where is the average branching factor (out-degree) and is the maximum path depth, as it may enumerate up to exponentially many paths in dense graphs.[39] The following pseudocode outlines a basic DFS for finding one path from source to target in an undirected graph, using adjacency list representation and a visited array:function DFS(u, t, visited, path):
path.append(u)
if u == t:
return true // path found, reconstruct from path array
visited[u] = true
for each neighbor v of u:
if not visited[v]:
if DFS(v, t, visited, path):
return true
path.pop()
return false
// Call: initialize visited as false, path empty; DFS(s, t, visited, path)
function DFS(u, t, visited, path):
path.append(u)
if u == t:
return true // path found, reconstruct from path array
visited[u] = true
for each neighbor v of u:
if not visited[v]:
if DFS(v, t, visited, path):
return true
path.pop()
return false
// Call: initialize visited as false, path empty; DFS(s, t, visited, path)