第3章データ構造とアルゴリズム
Complexity Classes計算量クラス
One subfield of computer science is theoretical computer science, which studies models of computation, their application to algorithms, and the complexity of problems. The complexity of a problem is the complexity (in terms of time or memory resources required) of the most efficient algorithms for solving the problem. Theoretical computer scientists are interested in understanding the difficulty of a problem in terms of time complexity, space complexity, and some other complexity measures.
英語のヒント
コンピューターサイエンスの一分野である理論計算機科学は、計算モデル、そのアルゴリズムへの応用、そして問題の計算量を研究する。問題の計算量とは、その問題を解く最も効率のよいアルゴリズムの、時間やメモリ資源についての計算量である。理論計算機科学者は、時間計算量、空間計算量、その他の尺度によって、問題の難しさを理解することに関心を持つ。
In this chapter, we have focused on solving problems known to have polynomial time algorithms. Searching, sorting, hashing, traversal, minimum spanning trees, or shortest paths are all examples of problems in the polynomial (P) time complexity class because they are all problems that have runtimes with a polynomial expression such as O(1), O(log N), O(N), O(N log N), O(N2), O(N3). In general, these problems are considered tractable because computers can solve them in a reasonable amount of time. But there are many problems that are considered intractable because they do not have efficient, polynomial-time algorithms.
英語のヒント
本章では、多項式時間のアルゴリズムがあるとわかっている問題を中心に解いてきた。探索、整列、ハッシュ法、走査、最小全域木、最短経路はすべて、多項式(P)時間計算量クラスに属する問題の例である。O(1)、O(log N)、O(N)、O(N log N)、O(N2)、O(N3)などの多項式の式で表される実行時間を持つ問題だからである。一般に、これらはコンピューターで妥当な時間内に解けるので、扱いやすい問題とされる。しかし、効率的な多項式時間アルゴリズムがないため、扱いにくいとされる問題も多い。
The nondeterministic polynomial (NP) time complexity class refers to all problems that can be solved in polynomial time by a nondeterministic algorithm. A nondeterministic algorithm is a special kind of Turing machine, which at each step can nondeterministically choose which instruction to execute, and is considered to successfully find a solution if any combination of these nondeterministic choices eventually lead to a correct solution. In other words, in contrast to a deterministic algorithm, such as a greedy algorithm, which must repeatedly apply a simple rule to deterministically select the next element in a solution, a nondeterministic algorithm is able to simultaneously explore all the possible choices. We do not yet have computers that can execute nondeterministic algorithms, but if we did, then we would be able to efficiently solve any combinatorial problem by relying on the special power of nondeterminism.
英語のヒント
非決定性多項式(NP)時間計算量クラスは、非決定性アルゴリズムで多項式時間に解ける、すべての問題を指す。非決定性アルゴリズムは、各段階で実行する命令を非決定的に選べる、特殊なチューリングマシンである。その選択の何らかの組合せが最終的に正しい解へ至れば、解を見つけることに成功したとみなされる。言い換えると、単純な規則を繰り返し適用し、次に解へ含める要素を決定的に選ぶ必要がある貪欲アルゴリズムなどと違い、非決定性アルゴリズムは、すべての可能な選択肢を同時に探索できる。これを実行するコンピューターはまだないが、もしあれば、非決定性という特別な力に頼って、どのような組合せ問題も効率よく解けるだろう。
Technically, all P problems are also NP problems because we already have deterministic algorithms for solving them and therefore do not need to rely on the special power of nondeterminism. For example, Dijkstra’s algorithm provides a deterministic polynomial-time solution to the shortest paths problem by building up a shortest paths tree from the start vertex outward. This application of the greedy algorithmic paradigm relies on the structure of the shortest paths tree, since the shortest path to a point further away from the start must build on the shortest path to a point closer to the start.
英語のヒント
厳密には、すべてのP問題はNP問題でもある。すでに決定性アルゴリズムで解けるため、非決定性の特別な力に頼る必要がないからである。たとえばダイクストラ法は、開始頂点から外側へ最短経路木を作ることで、最短経路問題に決定性多項式時間の解法を与える。この貪欲法の適用は、最短経路木の構造を利用している。開始点から遠い地点への最短経路は、より近い地点への最短経路に基づく必要があるからである。
NP-complete ProblemsNP完全問題
NP-complete refers to all the hardest NP problems—the combinatorial problems for which we do not have deterministic polynomial-time algorithms. More precisely, a problem PI is said to be NP-complete if PI is in NP and for every problem in NP, there is a reduction that reduces the problem to PI. For example, a longest path, or the problem of finding the highest-cost way to get from one vertex to another without repeating vertices, is an NP-complete problem opposite to shortest paths (Figure 3.32). What makes longest paths so much harder to solve than shortest paths? For one, there is no underlying structure to the solution that we can use to repeatedly apply a simple rule as in a greedy algorithm. With the shortest paths problem, we could rely on the shortest paths tree to inform the solution. But in longest paths, the goal is to wander around the graph. The longest path between any two vertices will probably involve traversing as many edges as possible to maximize distance, visiting many vertices along the way. For some graphs, the longest paths might even visit all the vertices in the graph. In this situation, the longest paths do not form a tree and instead involve ordering all the vertices in the graph for each longest path. Identifying the correct longest path then requires listing out all the possible paths in the graph—a combinatorial explosion in the combinations of edges and vertices that can be selected to form a solution.
英語のヒント
NP完全とは、NPの中で最も難しいすべての問題、すなわち決定性多項式時間アルゴリズムがない組合せ問題を指す。より正確には、問題PIがNPに属し、NPのすべての問題からPIへ帰着できるなら、PIはNP完全であるという。たとえば最長経路、すなわち頂点を繰り返し訪れずに、一方の頂点からもう一方へ最大コストで移動する方法を見つける問題は、最短経路とは逆のNP完全問題である(図3.32)。最長経路を解くのが、最短経路よりはるかに難しいのはなぜだろうか。まず、貪欲法のように単純な規則を繰り返し適用するために使える、解の基礎的な構造がない。最短経路では、最短経路木を解の指針にできたが、最長経路の目標は、グラフを歩き回ることである。任意の2頂点間の最長経路では、距離を最大にするため、できるだけ多くの辺を通り、途中で多くの頂点を訪れることになるだろう。グラフによっては、すべての頂点を訪れることさえある。この場合、最長経路群は木を作らず、最長経路ごとに、グラフのすべての頂点の順序を決めることになる。正しい最長経路を特定するには、可能なすべての経路を列挙しなければならない。解を作るために選ぶ辺と頂点の組合せが、組合せ爆発を起こすのである。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 3.32 The longest path in a graph maximizes the distance, which often (but not always) involves visiting many vertices along the way. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図3.32 グラフの最長経路は距離を最大にする。常にではないが、多くの場合、途中で多数の頂点を訪れることを伴う。(出典表記:著作権者 Rice University、OpenStax、CC BY 4.0ライセンス)
Related to the problem of longest paths is the traveling salesperson problem (TSP), which is the problem of, given the path cost of every pair of vertices, finding the lowest-cost tour, or path from a start vertex visiting every vertex in the graph once including a return to the start vertex. Compared to the TSP, which is finding the lowest-cost tour, the longest paths problem is like finding the highest-cost tour. What makes both these problems difficult is that we do not have a simple rule for selecting the next element to include in the solution. Unless we have the special power of nondeterminism, it is hard to tell from the beginning which edge is the right one to include in the final solution. Applying a simple rule like, “Select the edge with the lowest cost,” might not necessarily lead to the overall lowest-cost tour. Even though this simple rule worked for the problem of minimum spanning trees, the additional restriction of a tour rather than a tree makes the TSP a much harder problem to solve efficiently. Although we have efficient algorithms for shortest paths, we do not have efficient algorithms for the shortest tour (TSP).
英語のヒント
最長経路に関連するのが巡回セールスマン問題(TSP)である。各頂点の組の経路コストが与えられたとき、グラフのすべての頂点を1回ずつ訪れ、開始頂点へ戻る巡回路のうち、最小コストのものを求める。最小コストの巡回路を求めるTSPに対し、最長経路は最大コストの巡回路を求めるような問題である。両方の問題を難しくしているのは、次に解へ含める要素を選ぶ単純な規則がない点である。非決定性の特別な力がなければ、最終的な解に入れるべき辺がどれか、最初から見分けるのは難しい。「最小コストの辺を選ぶ」という単純な規則を使っても、巡回路全体のコストが最小になるとは限らない。この規則は最小全域木ではうまく働いたが、木ではなく巡回路であるという追加の制約によって、TSPを効率よく解くのは、はるかに難しくなる。最短経路の効率的なアルゴリズムはあるが、最短の巡回路(TSP)の効率的なアルゴリズムはない。