第3章データ構造とアルゴリズム
Minimum Spanning Trees最小全域木
Minimum spanning trees is the problem of finding a lowest-cost way to connect all the vertices to each other, where cost is the sum of the selected edge weights. The two canonical greedy algorithms for finding a minimum spanning tree in a graph are Kruskal’s algorithm and Prim’s algorithm. Both algorithms repeatedly apply the rule of selecting the next lowest-weight edge to an unconnected part of the graph. The output of a minimum spanning tree algorithm is a set of |V| - 1 edges connecting all the vertices in the graph with the least total sum of edge weights, where |V| is the number of vertices.
英語のヒント
最小全域木は、すべての頂点を互いに接続する最小コストの方法を見つける問題である。コストは、選んだ辺の重みの合計である。グラフの最小全域木を求める標準的な貪欲アルゴリズムには、クラスカル法とプリム法がある。どちらも、まだ接続されていない部分へ向かう辺のうち、次に重みの小さいものを選ぶ規則を繰り返す。最小全域木のアルゴリズムの出力は、重みの総和が最小で、グラフのすべての頂点を接続する|V| - 1本の辺の集合である。|V|は頂点数を表す。
Kruskal’s Algorithm
クラスカル法
Kruskal’s algorithm begins by considering each vertex as an independent "island," and the goal of the algorithm is to repeatedly connect islands by selecting the lowest-cost edges. A specialized data structure (called disjoint sets) is typically used to keep track of the independent islands. The runtime of Kruskal’s algorithm is in O(|E| log |E|) with respect to |E|, the number of edges (Figure 3.28).
英語のヒント
クラスカル法では、最初に各頂点を独立した「島」と考える。アルゴリズムの目標は、最小コストの辺を選んで、島同士を繰り返し接続することである。独立した島を管理するには、通常、互いに素な集合と呼ばれる専用のデータ構造を使う。クラスカル法の実行時間は、辺数|E|についてO(|E| log |E|)に属する(図3.28)。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 3.28 Kruskal’s algorithm repeatedly selects the next lightest edge that connects two independent "islands." (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図3.28 クラスカル法は、2つの独立した「島」を結ぶ、次に軽い辺を繰り返し選ぶ。(出典表記:著作権者 Rice University、OpenStax、CC BY 4.0ライセンス)
Prim’s Algorithm
プリム法
Prim’s algorithm grows a minimum spanning tree one edge at a time by selecting the lowest-weight edge to an unexplored vertex. The runtime of Prim’s algorithm is in O(|E| log |V| + |V| log |V|) with respect to |V|, the number of vertices, and |E|, the number of edges (Figure 3.29).
英語のヒント
プリム法は、未探索の頂点へ向かう最小の重みの辺を選び、1本ずつ最小全域木を成長させる。実行時間は、頂点数|V|と辺数|E|について、O(|E| log |V| + |V| log |V|)に属する(図3.29)。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 3.29 Prim’s algorithm expands outward from the start vertex by repeatedly selecting the next lightest edge to an unreached vertex. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図3.29 プリム法は、まだ到達していない頂点へ向かう、次に軽い辺を繰り返し選び、開始頂点から外側へ広がっていく。(出典表記:著作権者 Rice University、OpenStax、CC BY 4.0ライセンス)
Shortest Paths最短経路
The output of a shortest paths algorithm is a shortest paths tree, the lowest-cost way to get from one vertex to every other vertex in a graph (Figure 3.30). The unweighted shortest path is the problem of finding the shortest paths in terms of the number of edges. Given a start vertex, breadth-first search can compute the unweighted shortest paths tree from the start vertex to every other reachable vertex in the graph by maintaining a map data structure of the path used to reach each vertex.
英語のヒント
最短経路アルゴリズムの出力は、最短経路木である。これは、グラフのある頂点からほかのすべての頂点まで、最小コストで到達する方法を表す(図3.30)。重みのない最短経路問題では、辺の数で測って最短となる経路を求める。開始頂点が与えられれば、幅優先探索で、そこからグラフ内のすべての到達可能な頂点までの、重みのない最短経路木を計算できる。各頂点に到達した経路を、マップのデータ構造で保持すればよい。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 3.30 Three shortest paths trees of the lowest-cost way to get from the start vertex to every other vertex in the graph are shown. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図3.30 開始頂点からグラフ内のほかのすべての頂点まで、最小コストで到達する3つの最短経路木を示す。(出典表記:著作権者 Rice University、OpenStax、CC BY 4.0ライセンス)
Weighted Shortest Path
重み付き最短経路
A weighted shortest path is the problem of finding the shortest paths in terms of the sum of the edge weights. Earlier, we introduced Prim’s algorithm, a minimum spanning tree algorithm that maintains a priority queue of edges in the graph ordered by weight and repeatedly selects the next lowest-cost edge to an unconnected part of the graph.
重み付き最短経路は、辺の重みの総和で測って最短となる経路を求める問題である。先に紹介したプリム法は、グラフの辺を重み順に並べた優先度付きキューを維持し、未接続の部分へ向かう次にコストの小さい辺を繰り返し選ぶ、最小全域木のアルゴリズムである。
THINK IT THROUGH考えてみよう
Weighted Shortest Paths for Navigation Directions道案内のための重み付き最短経路
One of the most direct applications of the shortest paths problem is to provide recommended routes for navigation directions in real-world mapping. Many applications use distance as the metric for edge weight, so the shortest path between two points represents the real-world route with the smallest distance between the two places.
英語のヒント
最短経路問題の最も直接的な用途の1つは、現実の地図で道案内の推奨経路を示すことである。多くのアプリケーションは、辺の重みの尺度として距離を使う。そのため2地点間の最短経路は、実際にその2地点を結ぶ、距離の最も短い経路を表す。
What does a distance metric not consider when providing a recommended route? What values are centered and emphasized by even using a shortest paths algorithm for recommending routes?
英語のヒント
推奨経路を示すとき、距離という尺度は何を考慮しないだろうか。経路の推薦に最短経路アルゴリズムを使うこと自体によって、どのような価値が中心に置かれ、重視されるだろうか。
Dijkstra’s Algorithm
ダイクストラ法
Dijkstra’s algorithm maintains a priority queue of vertices in the graph ordered by distance from the start and repeatedly selects the next shortest path to an unconnected part of the graph. Dijkstra’s algorithm is almost identical to Prim’s algorithm except processing shortest paths (sequences of edges) rather than individual edges. Dijkstra’s algorithm grows a shortest paths tree one shortest path at a time by selecting the next shortest path to an unexplored vertex. The runtime of Dijkstra’s algorithm is in O(|E| log |V| + |V| log |V|) with respect to |V|, the number of vertices, and |E|, the number of edges (Figure 3.31).
英語のヒント
ダイクストラ法は、グラフの頂点を開始点からの距離で並べた優先度付きキューを維持し、未接続の部分に向かう次の最短経路を繰り返し選ぶ。個々の辺ではなく、最短経路、つまり辺の列を処理する点を除けば、プリム法とほぼ同じである。ダイクストラ法は、未探索の頂点へ向かう次の最短経路を選び、1経路ずつ最短経路木を成長させる。実行時間は、頂点数|V|と辺数|E|について、O(|E| log |V| + |V| log |V|)に属する(図3.31)。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 3.31 Dijkstra’s algorithm expands outward from the start vertex by repeatedly selecting the next lowest-cost path to an unreached vertex. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図3.31 ダイクストラ法は、まだ到達していない頂点へ向かう、次にコストの小さい経路を繰り返し選び、開始頂点から外側へ広がっていく。(出典表記:著作権者 Rice University、OpenStax、CC BY 4.0ライセンス)