markdown
最短路の基本md 11b9e7d
lecture/information/algorithm/graph/shortest-path-basics.lecture.n.md
Download PDF

最短路さいたんろ基本きほん

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

1導入どうにゅう

この講義こうぎでは、辺数へんすうまたは辺重へんおもみの総和そうわ最小化さいしょうかする最短路問題さいたんろもんだい定式化ていしきかし、BFS、ダイクストラほう負辺ふへんあつかえる方法ほうほう適用条件てきようじょうけん説明せつめいする。

グラフの頂点ちょうてんへん歩道ほどうみちと、BFSの層構造そうこうぞう前提ぜんていとする。

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

2グラフと経路けいろ定義ていぎ

有限ゆうげんグラフ G=(V,E)かんがえる。無向むこうグラフではへん {u,v}きがなく、有向ゆうこうグラフでは有向辺ゆうこうへん (u,v)u から v への移動いどうだけをゆるす。

s から t への歩道ほどうwalkとは、v0=s,v1,,vk=t という頂点列ちょうてんれつであり、連続れんぞくする二頂点にちょうてんむすへんEぞくするものをいう。有向ゆうこうグラフではへんきも一致いっちしなければならない。頂点ちょうてん反復はんぷくしない歩道ほどうみちpathぶ。辺数へんすうk である。

辺重へんおも関数かんすうedge-weight functionとは、各辺かくへん実数じっすう対応たいおうさせる関数かんすう w:ER である。歩道ほどう P=(v0,,vk)費用ひようcost

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

定義ていぎする。無向辺むこうへんでは w(vi-1,vi) を、その二頂点にちょうてんむす無向辺むこうへんおもみと解釈かいしゃくする。辺数へんすう最小化さいしょうかする問題もんだいは、すべてのへんおも1あたえた場合ばあい一致いっちする。

3距離きょり到達不能とうたつふのう

s から t への歩道ほどう費用ひよう下限かげん

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

定義ていぎする。s から t到達不能とうたつふのうである場合ばあいは、候補こうほ集合しゅうごうくうであるため δ(s,t)=+ とする。

閉歩道へいほどうclosed walkとは、始点してん終点しゅうてん一致いっちする歩道ほどうである。閉歩道へいほどうのうち、始点してん終点しゅうてんのぞいて頂点ちょうてん反復はんぷくせず、へん反復はんぷくしないものを閉路へいろcycleぶ。有向ゆうこうグラフの閉歩道へいほどうは、その分解ぶんかい負閉路ふへいろすくなくともひとふくむ。

s から到達可能とうたつかのうで、かつ t到達可能とうたつかのう閉歩道へいほどう存在そんざいすると、その閉歩道へいほどう任意回数にんいかいすうだけ反復はんぷくできる。この場合ばあいδ(s,t)=- であり、最小費用さいしょうひよう達成たっせいする歩道ほどう存在そんざいしない。無向むこうグラフでは、負辺ふへん往復おうふくする閉歩道へいほどう費用ひようになるため、その負辺ふへんs から t への経路けいろ利用りようできるなら距離きょり- である。

関連かんれんする負閉路ふへいろがなく、t到達可能とうたつかのうであるとする。任意にんいs から t への歩道ほどう頂点ちょうてん反復はんぷくするなら、そのあいだ閉歩道へいほどう費用ひよう非負ひふであり、これを除去じょきょしても費用ひよう増加ぞうかしない。この操作そうさ反復はんぷくするとみちる。有限ゆうげんグラフの s から t へのみち有限個ゆうげんこなので、その費用ひよう最小値さいしょうち達成たっせいするみち存在そんざいする。このみちs から t への最短路さいたんろぶ。

4おもみによる方法ほうほう選択せんたく

4.1ひとしい辺重へんおも

すべての辺重へんおもみがおなせい定数ていすう c>0 である場合ばあい費用ひよう辺数へんすうc ばいなので、費用ひよう最小化さいしょうか辺数へんすう最小化さいしょうか一致いっちする。BFSは始点してんからの辺数へんすう非減少ひげんしょうとなる順序じゅんじょ頂点ちょうてん処理しょりするため、各到達可能頂点かくとうたつかのうちょうてんへの最短距離さいたんきょり計算けいさんする。無重むおもみグラフは c=1解釈かいしゃくする。

4.2非負ひふ辺重へんおも

すべてのへんについて w(e)0 である場合ばあい、ダイクストラほう適用てきようできる。この方法ほうほうは、暫定距離ざんていきょり最小さいしょう未確定頂点みかくていちょうてん選択せんたくし、その頂点ちょうてん経由けいゆする候補経路こうほけいろによって隣接頂点りんせつちょうてん暫定距離ざんていきょり更新こうしんする。非負性ひふせいにより、確定済かくていずみの距離きょりあとから短縮たんしゅくする経路けいろ存在そんざいしない。

4.3負辺ふへん

負辺ふへんnegative edgeとは w(e)<0 であるへんをいう。負辺ふへん一辺いっぺんでも存在そんざいすると、未確定頂点みかくていちょうてん暫定距離ざんていきょりだけで確定かくていするダイクストラほう論拠ろんきょ成立せいりつしない。ただし、負辺ふへん存在そんざいだけでは最短路さいたんろ不存在ふそんざい意味いみしない。負閉路ふへいろ関連かんれんしない場合ばあいは、Bellman--Fordほうなど負辺ふへん許容きょようする方法ほうほう使用しようできる。

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

5最適部分構造さいてきぶぶんこうぞう

P=(v0,,vk)v0 から vk への最短路さいたんろとする。0i<jkたいし、部分道ぶぶんどう P[i:j]=(vi,,vj)vi から vj への最短路さいたんろである。これを最短路さいたんろ最適部分構造さいてきぶぶんこうぞうoptimal substructureぶ。

実際じっさいP[i:j] より費用ひようちいさい歩道ほどう Q存在そんざいすると仮定かていする。P当該部分とうがいぶぶんQ置換ちかんすれば、v0 から vk への費用ひようP よりちいさい歩道ほどう構成こうせいでき、P最短性さいたんせい矛盾むじゅんする。したがって主張しゅちょう成立せいりつする。この性質せいしつは、緩和かんわによって部分問題ぶぶんもんだい最良値さいりょうち結合けつごうする最短路さいたんろアルゴリズムの基礎きそとなる。

6まとめ

  • 無向むこう有向ゆうこうべつと、歩道ほどうみちべつ明示めいじしてから最短路問題さいたんろもんだい定式化ていしきかする。
  • 到達不能とうたつふのうなら距離きょり+ であり、関連かんれんする負閉路ふへいろがあれば - である。
  • 等重とうおもみではBFS、非負重ひふおもみではダイクストラほう適用てきようできる。負辺ふへんがある場合ばあいべつ方法ほうほう必要ひつようである。
  • 最短路さいたんろ任意にんい部分道ぶぶんどうも、その両端りょうたんあいだ最短路さいたんろである。

Shortest-Path Basics

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
タブを全て閉じる