第3章データ構造とアルゴリズム
Summaryまとめ
3.1 Introduction to Data Structures and Algorithms3.1 データ構造とアルゴリズム入門
• Data structures represent complex data types for solving real-world problems. Data structures combine specific data representations with specific functionality.
・データ構造は、現実の問題を解くための複雑なデータ型を表す。具体的なデータ表現と具体的な機能を組み合わせる。
• Abstract data types categorize data structures according to their functionality and ignore differences in data representation. Abstract data types include lists, sets, maps, priority queues, and graphs.
・抽象データ型は、データの表現方法の違いを無視し、機能に従ってデータ構造を分類する。リスト、集合、マップ、優先度付きキュー、グラフなどがある。
• To select an appropriate data structure, first select an abstract data type according to the problem requirements. Then, select an appropriate data structure implementation for the abstract data type.
・適切なデータ構造を選ぶには、まず問題の要件に従って抽象データ型を選び、その後、その型を実装する適切なデータ構造を選ぶ。
• Linear data structures organize elements in a line, ideal for implementing the list abstract data type. Linear data structures include array lists and linked lists.
・線形データ構造は要素を一列に整理し、リスト抽象データ型の実装に適している。配列リストと連結リストが含まれる。
• Linear data structures can implement any abstract data type. The study of data structures in general focuses on opportunities to improve efficiency (in terms of execution time or memory usage) over linear data structures.
・線形データ構造は、どの抽象データ型も実装できる。データ構造の研究では一般に、線形データ構造より実行時間やメモリ使用量の効率を改善できる機会に注目する。
• Tree data structures organize elements in a hierarchy of levels defined by parent-child relationships. Trees are defined with a root node at the top of the tree, parent-child relationships between each level, and leaf nodes at the bottom of the tree.
・木のデータ構造は、親子関係で定まるレベルの階層に要素を整理する。木は、最上部の根ノード、レベル間の親子関係、最下部の葉ノードによって定義される。
• Binary search trees require that elements in the tree are organized least-to-greatest from left-to-right. Binary search trees are often used to implement the set and map abstract data types.
・二分探索木では、木の要素が左から右へ小さい順に並ぶ必要がある。集合やマップの抽象データ型の実装によく使われる。
• Balanced binary search trees and binary heaps represent two approaches for avoiding the worst-case situation with binary search trees. Binary heaps are often used to implement the priority queue abstract data type.
・平衡二分探索木と二分ヒープは、二分探索木の最悪の状況を避ける2つの方法を表す。二分ヒープは、優先度付きキューの抽象データ型の実装によく使われる。
• Graph data structures focus on explicitly modeling the relationships between elements. Graphs afford access not only to elements, but also to the relationships between elements.
・グラフのデータ構造は、要素間の関係を明示的にモデル化することに重点を置く。要素だけでなく、要素間の関係にもアクセスできる。
3.2 Algorithm Design and Discovery3.2 アルゴリズムの設計と発見
• Just like how many data structures can represent the same abstract data type, many algorithms exist to solve the same problem. In algorithmic problem-solving, computer scientists solve formal problems with specific input data and output data that correspond to each input.
・多くのデータ構造が同じ抽象データ型を表せるのと同様に、同じ問題を解くアルゴリズムも多く存在する。アルゴリズムによる問題解決では、具体的な入力データと、各入力に対応する出力データを定めた形式的な問題を解く。
• Modeling is the process of representing a complex phenomenon such as a real-world problem as a formal problem. Modeling is about abstraction: the simplification or erasure of details so that the problem can be solved by a computer.
・モデル化は、現実世界の問題などの複雑な現象を、形式的な問題として表す過程である。抽象化、つまりコンピューターで解けるように細部を単純化したり、消し去ったりすることに関わる。
• Historically, the model of computation emphasized specialized algorithms operating on a modest model of the underlying phenomenon. Modeling is a violent but also necessary act in order to simplify the problem so that it can be solved by a computer.
・歴史的に、計算モデルは、背後の現象を比較的小規模に表したモデルを操作する、特化したアルゴリズムを重視してきた。モデル化は暴力的な行為であるが、コンピューターで解けるように問題を単純化するために必要な行為でもある。
• Searching is the problem of retrieving a target element from a collection of many elements. Sequential search and binary search are two algorithms for solving the search problem.
・探索は、多くの要素の集まりから目的の要素を取得する問題である。逐次探索と二分探索は、探索問題を解く2つのアルゴリズムである。
• To solve real-world problems, computer scientists compose, modify, and apply algorithm design patterns, such as search algorithms.
・現実の問題を解くため、コンピューター科学者は、探索アルゴリズムなどの設計パターンを組み合わせ、変更し、適用する。
• Algorithm analysis is the study of the outputs produced by an algorithm as well as how the algorithm produces those outputs.
・アルゴリズム解析は、アルゴリズムの出力と、それをどのように生み出すかを研究することである。
• Correctness considers whether the outputs produced by an algorithm match the expected or desired results across the range of possible inputs. Correctness is defined as a match between the algorithm and the model of the problem, not between the algorithm and the real-world.
・正しさでは、あり得る入力の範囲全体で、出力が期待される結果や望ましい結果と一致するかを検討する。正しさは、アルゴリズムと現実世界との一致ではなく、アルゴリズムと問題モデルとの一致として定義される。
• Correctness is complicated by the complexity of social relationships, power, and inequity in the real-world. Since algorithms automate processes and operate in existing power structures, they are likely to reproduce and amplify social injustice.
・現実世界の社会関係、権力、不公平の複雑さが、正しさを複雑なものにする。アルゴリズムは処理を自動化し、既存の権力構造の中で動作するため、社会的不正義を再生産し、増幅しやすい。
• In addition to correctness, computer scientists are also interested in complexity, or measuring the computational resources that an algorithm consumes during its execution in relation to the size of the input.
・コンピューター科学者は、正しさだけでなく計算量、すなわち入力サイズとの関係で、アルゴリズムが実行中に消費する計算資源を測ることにも関心を持つ。
3.3 Formal Properties of Algorithms3.3 アルゴリズムの形式的性質
• Runtime analysis is a study of how much time it takes to run an algorithm. Experimental analysis is a runtime analysis technique that involves evaluating an algorithm’s runtime by recording how long it takes to run a program implementation of it.
・実行時間解析は、アルゴリズムの実行に必要な時間の研究である。実験による分析は、そのアルゴリズムを実装したプログラムの実行時間を記録して評価する、実行時間解析の手法である。
• Time complexity is the formal measure of how much time an algorithm requires during execution as it relates to the size of the problem. The goal of time complexity analysis is to produce a simple and easy-to-compare characterization of the runtime of an algorithm as it relates to the size of the problem.
・時間計算量は、問題のサイズとの関係で、実行中に必要な時間を形式的に表す尺度である。時間計算量解析の目標は、問題のサイズとの関係で、実行時間を単純で比較しやすく記述することである。
• Space complexity is the formal measure of how much memory an algorithm requires during execution as it relates to the size of the problem.
・空間計算量は、問題のサイズとの関係で、アルゴリズムが実行中に必要とするメモリ量を形式的に表す尺度である。
• Steps in time complexity analysis are to identify a metric for representing the size of the problem; to model the number of steps needed to execute the algorithm; and to formalize the model using either precise English or asymptotic notation to define the order of growth. Big O notation is the most common type of asymptotic notation in computer science.
・時間計算量解析では、問題のサイズを表す尺度を特定し、実行に必要なステップ数をモデル化し、正確な英語または漸近記法でモデルを形式化して、増加のオーダーを定める。ビッグO記法は、コンピューターサイエンスで最も一般的な漸近記法である。
• Differences in orders of growth are massive: as the input size grows, the difference between orders of growth becomes more and more vast. For problems dealing with just 1,000 elements, the time it would take to run an exponential-time algorithm on that problem exceeds the current age of the universe—whereas that same-size problem running on the same computer would take just 1 second on a quadratic-time algorithm.
・増加のオーダーの違いは非常に大きい。入力サイズが増えると、その差はますます広がる。わずか1,000個の要素を扱う問題でも、指数時間アルゴリズムの実行時間は現在の宇宙の年齢を超える。一方、同じサイズの問題を同じコンピューターの2次時間アルゴリズムで実行すると、わずか1秒で済む。
• In practice, across applications working with large amounts of data, O(N2) is often considered the limit for real-world algorithms. For algorithms that need to run frequently on large amounts of data, algorithm designers target O(N), O(log N), or O(1).
・大量のデータを扱う実際のアプリケーションでは、O(N2)が実用的なアルゴリズムの限界とみなされることが多い。大量のデータに対して頻繁に実行する必要がある場合、設計者はO(N)、O(log N)、O(1)を目指す。