Hubbry Logo
Path (graph theory)Path (graph theory)Main
Open search
Path (graph theory)
Community hub
Path (graph theory)
logo
8 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Path (graph theory)
Path (graph theory)
from Wikipedia
A three-dimensional hypercube graph showing a Hamiltonian path in red, and a longest induced path in bold black

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]

References

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
In , a path is a walk in a graph where no vertex is repeated, consisting of a sequence of distinct vertices connected by edges such that each pair of consecutive vertices is adjacent. This ensures that the path forms a without revisiting any nodes, distinguishing it from more general walks that allow vertex repetitions and trails that permit vertex repeats but not edge repeats. The length of a path is defined as the number of edges it contains, often denoted as the distance between its endpoints in connected graphs. Paths play a central role in analyzing graph connectivity and structure, as the existence of a path between two vertices determines whether they belong to the same connected component. In undirected graphs, any shortest walk between vertices is guaranteed to be a path, providing the minimal route without detours. Key variants include directed paths in digraphs, which follow edge orientations, and Hamiltonian paths, which visit every vertex exactly once—a problem central to the P vs. NP complexity question. Paths also underpin algorithms for network routing, such as Dijkstra's algorithm for finding shortest paths in weighted graphs with non-negative edge weights. Beyond basic definitions, paths relate to cycles—closed paths where the first and last vertices coincide, excluding trivial repetitions—and enable the study of graph properties like acyclicity in trees, where every pair of vertices is connected by exactly one path. In applications, paths model routes in transportation networks, dependencies in scheduling, and traversals in computer science, highlighting their versatility across theoretical and practical domains.

Definitions

Walks, Trails, and Paths

In , a walk in an undirected graph G=(V,E)G = (V, E) is formally defined as an alternating sequence of vertices and edges v0,e1,v1,e2,,ek,vkv_0, e_1, v_1, e_2, \dots, e_k, v_k, where each viVv_i \in V, each eiEe_i \in E, and eie_i is incident to vi1v_{i-1} and viv_i for i=1,,ki = 1, \dots, k. Walks permit repetitions of both vertices and edges, allowing arbitrary traversal through the graph. A trail is a walk in which no edge is repeated. Thus, trails may revisit vertices but must use each edge at most once, providing a that avoids redundant edge usage while potentially looping back through shared vertices. A path is a trail in which no vertex is repeated, except possibly the initial and terminal vertices in the case of closed variants. For open paths, all vertices are distinct, ensuring a simple progression from start to end without revisiting any vertex. The of a walk, trail, or path is the number of edges in the sequence, so a path of length kk consists of kk edges and k+1k+1 distinct vertices. Walks, trails, and paths form a hierarchy: every path is a trail, and every trail is a walk, with increasing restrictions on repetitions. A walk, trail, or path is closed if its initial vertex equals its terminal vertex (v0=vkv_0 = v_k); a closed path (with no other repeated vertices) is known as a cycle.

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 of vertices and directed edges v0,e1,v1,e2,,ek,vkv_0, e_1, v_1, e_2, \dots, e_k, v_k such that each edge eie_i is directed from vi1v_{i-1} to viv_i for 1ik1 \leq i \leq k. 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. Thus, while vertices may repeat, each arc appears at most once in the sequence. A directed path is a directed in which no vertex is repeated (except possibly the start and end in closed cases). Directed paths are denoted as a uvu \to v path, indicating a sequence from vertex uu to vertex vv that follows the edge orientations without revisiting intermediate vertices. In directed graphs, the existence of a directed path from uu to vv defines reachability, meaning vv can be accessed from uu by following the prescribed directions. 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. This structure must traverse arcs in their oriented direction, distinguishing it from undirected counterparts by enforcing one-way traversal.

Properties

Length and Simplicity

In , the length of a path is defined as the number of edges it contains in unweighted graphs. In weighted graphs, the length is instead the sum of the weights assigned to those edges. Formally, for a path PP, its length is given by E(P)|E(P)|, where E(P)E(P) denotes the set of edges in PP. A simple path is a path that contains no repeated vertices, ensuring that all vertices in the sequence are distinct. This property aligns with the standard definition of a path in many contexts, where paths are inherently simple to avoid redundancy. 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. In connected undirected graphs, the existence of a simple path between any two vertices establishes that those vertices belong to the same connected component. 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.

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. 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. 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. 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 . 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. Forests and thus serve as building blocks for understanding more complex graphs, where the introduction of even a single cycle alters connectivity and traversal properties fundamentally. 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. This process highlights how cycles represent detours in non-simple structures, allowing reduction to path-like efficiency without altering the overall connectivity. Special cases of circuits include the Eulerian circuit, which is a closed that covers every edge in the graph exactly once, providing a complete traversal without edge reuse. 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. These constructs extend the closed-path paradigm to global graph properties, influencing problems in connectivity and optimization.

Illustrations

Basic Examples

In graph theory, a fundamental illustration of a path is the PnP_n, which consists of nn vertices connected in a linear chain by n1n-1 edges, such as v1v2vnv_1 - v_2 - \dots - v_n. 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, P4P_4 shows vertices 1-2-3-4 forming the path sequence 1-2-3-4. 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., P4P_4). 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 , since it repeats the edge between 1 and 2. Another basic example arises in the complete graph K3K_3, a 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. In directed graphs, paths follow edge orientations. A graph, where every pair of distinct vertices has exactly one directed edge between them, always contains a directed visiting each vertex exactly once, such as from a source vertex (with out-degree n1n-1) to a (with in-degree n1n-1) in a simple transitive like 1→2→3→4. The , 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.

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. In complete graphs KnK_n, where every pair of distinct vertices is connected by a single edge, the path between any two vertices is trivially of 1 via the direct edge; moreover, for n2n \geq 2, Hamiltonian paths exist that visit each vertex exactly once, such as the sequence ordering all vertices linearly. In bipartite graphs, with vertex set partitioned into two AA and BB such that all edges connect vertices between AA and BB, any path must alternate between the two partitions, starting in one and switching with each step; consequently, the of the longest path (in terms of edges) is bounded by the partition sizes, at most A+B1|A| + |B| - 1, but more tightly limited to roughly twice the size of the smaller partition due to the alternation constraint. For directed acyclic graphs (DAGs), a 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. In grid graphs, which form a lattice structure like an m×nm \times n of vertices connected horizontally and vertically, there are typically multiple shortest paths between opposite corners, such as from (0,0)(0,0) to (m,n)(m,n), with the exact number given by the (m+nm)\binom{m+n}{m}, representing the ways to choose horizontal moves among the total steps.

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 uu reaches vv if there exists a path from uu to vv. In undirected graphs, this corresponds to checking if the vertices lie in the same connected component, which can be identified using traversal algorithms. 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. DFS starts from a source vertex ss and recursively visits adjacent unvisited vertices, marking them to avoid cycles, until it reaches the target tt or exhausts all possibilities. The algorithm runs in O(V+E)O(|V| + |E|) time, linear in the graph size, making it efficient for sparse graphs. To find an actual path, DFS can maintain a parent pointer or path stack during traversal. For unweighted graphs, (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. , originally described for shortest paths, processes vertices in order of increasing distance from ss, ensuring the first encounter of tt yields the minimal-length path. Like DFS, it operates in O(V+E)O(|V| + |E|) time. Enumerating all simple paths—those without repeated vertices—between two vertices requires backtracking, an extension of DFS that systematically explores all possible extensions while cycles by tracking visited vertices in the current path. This approach builds paths incrementally, adding adjacent vertices and recursing until reaching the target or backtracking upon dead ends or cycles. The time complexity is exponential, typically O(bd)O(b^d), where bb is the average (out-degree) and dd is the maximum path depth, as it may enumerate up to exponentially many paths in dense graphs. The following pseudocode outlines a basic DFS for finding one path from source ss to target tt 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)

This recursive implementation detects existence and can be modified for full enumeration by collecting all successful paths.

Shortest Path Computation

In , computing the shortest path between vertices involves finding a path of minimal total edge weight, a fundamental problem with applications in , network , and optimization. For unweighted graphs, where all edges have equal weight, (BFS) efficiently constructs a from a source vertex, exploring vertices level by level to guarantee minimality in O(V + E) time, as each vertex and edge is visited exactly once. This approach leverages the uniform cost to treat the graph as a tree of increasing distances from the source. Dijkstra's algorithm extends this idea to weighted graphs with non-negative edge weights, using a greedy strategy with a to select the next vertex with the smallest tentative . It maintains estimates updated via relaxation and runs in O((V + E) log V) time with a , making it suitable for sparse graphs. The algorithm fails with negative weights due to potential non-monotonic updates but remains a for problems like GPS . For graphs with negative edge weights but no negative cycles, the Bellman-Ford algorithm iteratively relaxes all edges up to V-1 times, computing shortest paths in O(VE) time and detecting negative cycles via an additional relaxation pass. Originating from network flow theory, it handles arbitrary topologies but is less efficient for dense graphs compared to alternatives. The Floyd-Warshall algorithm computes all-pairs shortest paths using dynamic programming, initializing a with direct edge weights and iteratively improving paths through each intermediate vertex k: dmin(d,d+d)d \leftarrow \min(d, d + d) for all i, j, achieving O(V^3) time regardless of edge density, ideal for small to medium graphs. It accommodates negative weights without cycles and naturally detects them through diagonal checks. A* search enhances Dijkstra's method for large-scale graphs by incorporating a estimate of remaining to the goal, prioritizing nodes via f(n) = g(n) + h(n), where g(n) is the path cost from start and h(n) is admissible (never overestimating). This informed search reduces explored nodes in practice, excelling in domains like and video games where domain knowledge provides effective heuristics.

Special Problems

Path Partition

The path partition number, denoted χp(G)\chi_p(G), of a graph GG is defined as the smallest number of vertex-disjoint paths whose union covers every vertex of GG exactly once. This minimum path cover problem seeks to decompose the vertex set into as few induced paths as possible, providing a measure of how "path-like" the graph is in terms of vertex covering. The problem is fundamental in , with applications in scheduling, network design, and . In directed acyclic graphs (DAGs), the path partition number has a precise characterization via , which states that χp(G)\chi_p(G) equals the cardinality of a maximum in the partial order induced by the DAG's . An is a set of pairwise incomparable elements (vertices with no directed path between them), and the theorem equates this size to the minimum number of directed chains (paths) needed to cover the poset. This equivalence holds because chains correspond directly to directed paths in the DAG. For DAGs, computing χp(G)\chi_p(G) is solvable in polynomial time using a bipartite matching reduction. Construct a bipartite graph BB with partite sets LL and RR, both copies of V(G)V(G), and an edge from uLu \in L to vRv \in R if there is a directed edge uvu \to v in GG. The size of a maximum matching in BB equals the maximum number of "links" that can be chained into paths, so χp(G)=V(G)M\chi_p(G) = |V(G)| - M, where MM is the matching size. This reduction leverages Hopcroft-Karp or similar algorithms for efficient computation, running in O(E(G)V(G))O(|E(G)| \sqrt{|V(G)|})
Add your contribution
Related Hubs
User Avatar
No comments yet.