markdown
Shortest-Path Basicsmd 11b9e7d
lecture/information/algorithm/graph/shortest-path-basics.lecture.n.md
Download PDF

Shortest-Path Basics

date2026-07-14document_iddoc_cfb7aa8638aa4a6bd358edf029cbe4c6description最短路問題の定義を厳密に整理し、BFS、ダイクストラ法、負辺を扱う方法の適用条件を説明する。prerequisitesグラフの基本 / DFSとBFSの基本 / 計算量の基本type講義statusactiverelateddata/lecture/information/algorithm/graph/graph-algorithms-portal.lecture.n.md / data/lecture/information/algorithm/search/dfs-and-bfs-basics.lecture.n.md / data/lecture/information/algorithm/graph/dijkstra-algorithm-basics.lecture.n.md
algorithmgraphundergraduatelecture

1Introduction

This lecture formulates shortest-path problems that minimize either the number of edges or the sum of edge weights. It then explains the applicability conditions for BFS, Dijkstra's algorithm, and methods that permit negative edges.

The lecture assumes the definitions of vertices, edges, walks, and paths, together with the layered structure of BFS.

data/lecture/information/graph/graph-basics.lecture.n.md data/lecture/information/algorithm/search/dfs-and-bfs-basics.lecture.n.md

2Graphs and routes

Let G=(V,E) be a finite graph. An edge {u,v} of an undirected graph has no orientation, whereas a directed edge (u,v) permits movement only from u to v.

An s-to-t walk is a vertex sequence v0=s,v1,,vk=t in which an edge of E joins every pair of consecutive vertices. In a directed graph, each edge orientation must also agree with the sequence. A walk with no repeated vertex is a path. Its number of edges is k.

An edge-weight function is a function w:ER that assigns a real number to each edge. The cost of a walk P=(v0,,vk) is

c(P)=i=1kw(vi-1,vi).

For an undirected edge, w(vi-1,vi) denotes the weight of the undirected edge joining those two vertices. Minimizing the number of edges is equivalent to assigning weight 1 to every edge.

3Distance and unreachability

Define the distance from s to t as the infimum of the costs of all s-to-t walks:

δ(s,t)=inf{c(P)Pisans[PARSE ERROR: Undefined("RBrace")]twalk}.

If t is unreachable from s, the candidate set is empty, and we define δ(s,t)=+.

A closed walk is a walk whose first and last vertices coincide. A cycle is a closed walk with no repeated vertices other than its coincident endpoints. In a directed graph, every negative closed walk contains at least one negative cycle in its decomposition.

Suppose a negative cycle is reachable from s and t is reachable from that cycle. Repeating the cycle arbitrarily many times gives δ(s,t)=-, and no walk attains a minimum cost. In an undirected graph, traversing a negative edge in both directions forms a negative closed walk. Thus the distance is - whenever such an edge can occur on an s-to-t route.

Now suppose that no relevant negative cycle exists and that t is reachable. If an arbitrary s-to-t walk repeats a vertex, the intervening closed subwalk has nonnegative cost and can be removed without increasing the cost. Repeating this operation produces a path. A finite graph has only finitely many s-to-t paths, so one of them attains the minimum cost. Such a path is called a shortest path from s to t.

4Choosing a method from the weights

4.1Equal edge weights

If all edge weights equal the same positive constant c>0, the cost is c times the number of edges. Thus minimizing cost is equivalent to minimizing the number of edges. BFS processes vertices in nondecreasing order of their edge counts from the source, so it computes the shortest distance to every reachable vertex. An unweighted graph is interpreted as the case c=1.

4.2Nonnegative edge weights

If w(e)0 for every edge, Dijkstra's algorithm applies. It selects an unsettled vertex with minimum tentative distance and uses candidate routes through that vertex to update the tentative distances of adjacent vertices. Nonnegativity ensures that no later route can decrease a settled distance.

4.3Negative edges

A negative edge is an edge e with w(e)<0. If even one negative edge exists, the justification for settling vertices solely by tentative distance in Dijkstra's algorithm no longer holds. A negative edge alone, however, does not imply that a shortest path fails to exist. If no relevant negative cycle exists, a method that permits negative edges, such as the Bellman--Ford algorithm, can be used.

data/lecture/information/algorithm/graph/dijkstra-algorithm-basics.lecture.n.md

5Optimal substructure

Let P=(v0,,vk) be a shortest path from v0 to vk. For every 0i<jk, the subpath P[i:j]=(vi,,vj) is also a shortest path from vi to vj. This property is called the optimal substructure of shortest paths.

Indeed, suppose that a walk Q from vi to vj had lower cost than P[i:j]. Replacing that portion of P with Q would construct a walk from v0 to vk with lower cost than P, contradicting the optimality of P. The claim therefore holds. This property underlies shortest-path algorithms that combine optimal values of subproblems through relaxation.

6Summary

  • A shortest-path problem must specify whether the graph is directed or undirected and distinguish walks from paths.
  • The distance is + when the target is unreachable and - when a relevant negative cycle exists.
  • BFS applies to equal weights, and Dijkstra's algorithm applies to nonnegative weights. Negative edges require a different method.
  • Every subpath of a shortest path is itself a shortest path between its endpoints.
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる