第3章データ構造とアルゴリズム
3.4 Algorithmic Paradigms3.4 アルゴリズムの基本的な考え方
• Algorithmic paradigms are the common concepts and ideas behind algorithm design patterns, such as divide and conquer algorithms, brute-force algorithms, greedy algorithms, and reduction algorithms.
・アルゴリズムのパラダイムは、設計パターンの背後にある共通の概念や考え方である。分割統治、総当たり、貪欲、帰着の各アルゴリズムなどがある。
• Divide and conquer algorithms break down a problem into smaller subproblems (divide), recursively solve each subproblem (conquer), and then combine the result of each subproblem to inform the overall solution. Recursion is an algorithm idea fundamental to divide and conquer algorithms that solves complex problems by dividing input data into smaller, independent instances of the same problem known as subproblems.
・分割統治アルゴリズムは、問題を小さい部分問題へ分け(分割)、各部分問題を再帰的に解き(統治)、それぞれの結果を組み合わせて全体の解に反映する。再帰は、その基礎となる考え方であり、入力データを部分問題と呼ばれる、同じ問題の小さく独立した事例へ分け、複雑な問題を解く。
• Binary search is an example of divide and conquer algorithm with a single recursive subproblem. Merge sort is an example of a divide and conquer algorithm with two recursive subproblems.
・二分探索は、再帰的な部分問題が1つの分割統治アルゴリズムの例である。マージソートは、再帰的な部分問題が2つの例である。
• Brute-force algorithms solve combinatorial problems by systematically enumerating all potential solutions in order to identify the best candidate solution. Combinatorial problems identify the best candidate solution out of a space of many potential solutions.
・総当たりアルゴリズムは、可能なすべての解を体系的に列挙し、最良の解候補を特定して、組合せ問題を解く。組合せ問題では、多くの可能な解の空間から、最良の候補を見つける。
• Brute-force algorithms exist for every combinatorial problem, but they are not typically used in practice because of long run time issues. To enumerate all potential solutions, a brute-force algorithm must generate every possible combination of the input data.
・すべての組合せ問題に総当たりアルゴリズムは存在するが、実行時間が長いため、実際には通常使われない。すべての可能な解を列挙するには、入力データから作れるすべての組合せを生成しなければならない。
• Greedy algorithms solve combinatorial problems by repeatedly applying a simple rule to select the next element to include in the solution. Unlike brute-force algorithms that solve combinatorial problems by generating all potential solutions, greedy algorithms instead focus on generating just one solution.
・貪欲アルゴリズムは、単純な規則を繰り返し、次に解へ含める要素を選んで組合せ問題を解く。すべての解候補を生成する総当たりアルゴリズムと異なり、1つの解だけを生成することに注目する。
• Greedy algorithms are not always guaranteed to compute the best solution depending on the assumptions and goals of the problem. A greedy algorithm for the interval scheduling problem will not compute the correct result if we choose to complete the shortest tasks.
・貪欲アルゴリズムは、問題の仮定や目標によっては、最良の解を計算できると保証されない。区間スケジューリングでは、最短の作業を完了するように選ぶ貪欲アルゴリズムは、正しい結果を計算しない。
• Kruskal’s algorithm and Prim’s algorithm are two examples of greedy algorithms for the minimum spanning trees problem. These algorithms are a rare example of a greedy algorithm that is guaranteed to compute the correct result.
・クラスカル法とプリム法は、最小全域木問題の貪欲アルゴリズムの2つの例である。正しい結果を計算すると保証される、珍しい貪欲アルゴリズムである。
• Reduction algorithms solve problems by transforming them into other problems. In other words, reduction algorithms delegate most of the work of solving the problem to another algorithm meant for a different problem.
・帰着アルゴリズムは、問題をほかの問題へ変換して解く。つまり、問題を解く仕事の大半を、別の問題向けのアルゴリズムに任せる。
• Reduction algorithms allow algorithm designers to rely on optimized canonical algorithms rather than designing a solution by composing algorithm design patterns, which can lead to performance or correctness bugs. Reduction algorithms also enable computer scientists to make claims about the relative difficulty of a problem.
・帰着アルゴリズムを使うと、性能や正しさのバグにつながる可能性がある設計パターンの組合せによる解法設計ではなく、最適化された標準的なアルゴリズムに頼れる。また、問題の相対的な難しさについて主張することもできる。
3.5 Sample Algorithms by Problem3.5 問題別のアルゴリズムの例
• Data structure problems focus on the storage and retrieval of elements for implementing abstract data types such as lists, sets, maps, and priority queues. Data structure problems include sorting, searching, and hashing.
・データ構造の問題は、リスト、集合、マップ、優先度付きキューなどの抽象データ型を実装するため、要素の保存と取得に注目する。整列、探索、ハッシュ法が含まれる。
• Searching is the problem of retrieving a target element from a collection of elements. Searching in a linear data structure such as an array list can be done using either sequential search or binary search.
・探索は、要素の集まりから目的の要素を取得する問題である。配列リストなどの線形データ構造では、逐次探索または二分探索で実行できる。
• Sorting is the problem of rearranging elements into a logical order, typically from least-valued (smallest) to greatest-valued (largest). Sorting is a fundamental problem not only because of the tasks that it directly solves, but also because it is a foundation for many other algorithms such as the binary search algorithm or Kruskal’s algorithm for the minimum spanning tree problem.
・整列は、要素を論理的な順序、通常は値の小さいものから大きいものへ並べ替える問題である。直接解決する作業に加え、二分探索や最小全域木のクラスカル法など、多くのアルゴリズムの基礎となる点でも、基本的な問題である。
• Merge sort and quicksort are two examples of divide and conquer algorithms for sorting. Heapsort is a sorting algorithm that relies on adding to a heap and then repeatedly removing each element in sorted order.
・マージソートとクイックソートは、整列のための分割統治アルゴリズムの2つの例である。ヒープソートは、要素をヒープへ追加し、その後、整列順に1つずつ繰り返し取り出すことに基づく整列アルゴリズムである。
• Hashing is the problem of assigning a meaningful integer index (hash value) for each object. Hash tables are a data structure for implementing sets and maps by applying the concept of hashing.
・ハッシュ法は、各オブジェクトに意味のある整数のインデックス(ハッシュ値)を割り当てる問題である。ハッシュテーブルは、その考え方を使って集合やマップを実装するデータ構造である。
• Graph problems include a wide variety of problems involving the graph data type. Graph problems include traversal, minimum spanning trees, and shortest paths.
・グラフの問題は、グラフのデータ型に関わる幅広い問題を含む。走査、最小全域木、最短経路などがある。
• Traversal is the problem of exploring all the vertices in a graph. Depth-first search and breadth-first search are both graph traversal algorithms that expand outward from a start vertex, ultimately visiting every reachable vertex.
・走査は、グラフのすべての頂点を調べる問題である。深さ優先探索と幅優先探索は、どちらも開始頂点から外側へ広がり、最終的に到達可能なすべての頂点を訪れるグラフ走査アルゴリズムである。
• 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.
・最小全域木は、すべての頂点を互いに接続する、最小コストの方法を見つける問題である。コストは、選んだ辺の重みの総和である。グラフの最小全域木を見つける標準的な貪欲アルゴリズムは、クラスカル法とプリム法である。
• Shortest paths is the problem of finding a lowest-cost way to get from one vertex to another. The output of a shortest paths algorithm is a shortest paths tree from the start vertex to every other vertex in the graph.
・最短経路は、一方の頂点から別の頂点へ最小コストで移動する方法を見つける問題である。そのアルゴリズムの出力は、開始頂点からグラフ内のほかのすべての頂点までの最短経路木である。
• Breadth-first search computes the unweighted shortest paths tree, the shortest paths in terms of the number of edges. Dijkstra’s algorithm computes the weighted shortest paths tree, the shortest paths in terms of the sum of the edge weights.
・幅優先探索は、辺の数で測った最短経路である、重みのない最短経路木を計算する。ダイクストラ法は、辺の重みの総和で測った最短経路である、重み付き最短経路木を計算する。