プリンキピア

第3章データ構造とアルゴリズム

3.2 Algorithm Design and Discovery3.2 アルゴリズムの設計と発見

Learning Objectives学習目標
By the end of this section, you will be able to:
この節を終えると、次のことができるようになる。
• Understand the approach to solving algorithmic problems
・アルゴリズムの問題を解くための方法を理解する。
• Explain how algorithm design patterns are used to solve new problems
・アルゴリズムの設計パターンを使って新しい問題を解く方法を説明する。
• Describe how algorithms are analyzed
・アルゴリズムを分析する方法を述べる。
Our introduction to data structures focused primarily on representing complex data. But computer scientists are also interested in designing algorithms for solving a wider variety of problems beyond storing and retrieving data. For example, they may want to plan a route between a start location and an end location on a map. Although every real-world problem is unique, computer scientists can use a general set of principles to design solutions without needing to develop new algorithms from scratch. Just like how many data structures can represent the same abstract data type, many different solutions exist to solve the same problem.
英語のヒント
データ構造の導入では、複雑なデータの表現を中心に扱った。しかし、コンピューター科学者の関心は、データの保存や取得だけでなく、さらに多様な問題を解くためのアルゴリズムの設計にもある。たとえば地図上の出発地点から目的地点までの経路を計画したいこともある。現実世界の問題はそれぞれ異なるが、一般的な一連の原理を使えば、毎回新しいアルゴリズムをゼロから開発せずに、解決方法を設計できる。同じ抽象データ型を多くのデータ構造で表せるのと同様に、同じ問題を解くための解法も多く存在する。

Algorithmic Problem Solvingアルゴリズムによる問題解決

An algorithm is a sequence of precise instructions that takes any input and computes the corresponding output, while algorithmic problem-solving refers to a particular set of approaches and methods for designing algorithms that draws on computing’s historical connections to the study of mathematical problem solving. Early computer scientists were influenced by mathematical formalism and mathematical problem solving. George Pólya’s 1945 book, How to Solve It, outlines a process for solving problems that begins with a formal understanding of the problem and ends with a solution to the problem. As an algorithm's input size is always finite, finding a solution to an algorithmic problem can always be accomplished by exhaustive search. Therefore, the goal of algorithmic problem-solving, as opposed to mathematical problem solving, is to find an “efficient” solution, either in terms of execution time (e.g., number of computer instructions) or space used (e.g., computer memory size). Consequently, the study of algorithmic problem-solving emphasizes the formal problem or task, with specific input data and output data corresponding to each input. There are many other ways to solve problems with computers, but this mathematical approach remains the dominant approach in the field. Here are a few well-known problems in computer science that we will explore later in this chapter.
英語のヒント
アルゴリズムは、任意の入力を受け取って対応する出力を計算する、正確な指示の列である。一方、アルゴリズムによる問題解決とは、計算と数学的な問題解決の研究との歴史的なつながりを土台とする、アルゴリズム設計のための特定の考え方や方法の集まりを指す。初期のコンピューター科学者は、数学的形式主義や数学的な問題解決の影響を受けた。ジョージ・ポリアの1945年の著書『いかにして問題をとくか』は、問題の形式的な理解から始まり、解決に至る過程を示している。アルゴリズムの入力サイズは常に有限なので、アルゴリズムの問題の解は、全探索によって必ず見つけられる。したがって、数学的な問題解決とは異なり、アルゴリズムによる問題解決の目標は、実行時間(たとえばコンピューターの命令の数)または使う空間(たとえばコンピューターのメモリ量)の点で「効率的な」解を見つけることである。そのため、アルゴリズムによる問題解決の研究では、具体的な入力データと、それぞれの入力に対応する出力データを定めた、形式的な問題や課題を重視する。コンピューターで問題を解く方法はほかにも多いが、この数学的な方法が、この分野では依然として主流である。本章の後半で扱う、コンピューターサイエンスのよく知られた問題をいくつか紹介する。
A data structure problem is a computational problem involving the storage and retrieval of elements for implementing abstract data types such as lists, sets, maps, and priority queues. These include:
英語のヒント
データ構造の問題とは、リスト、集合、マップ、優先度付きキューなどの抽象データ型を実装するために、要素を保存したり取得したりする計算上の問題である。次のようなものがある。
• searching, or the problem of retrieving a target element from a collection of elements
・探索。要素の集まりから、目的の要素を取得する問題。
• sorting, or the problem of rearranging elements into a logical order
英語のヒント
・整列。要素を論理的な順序へ並べ替える問題。
• hashing, or the problem of assigning a meaningful integer index for each object
英語のヒント
・ハッシュ法。各オブジェクトに、意味のある整数のインデックスを割り当てる問題。
A graph problem is a computational problem involving graphs that represent relationships between data. These include:
グラフの問題とは、データ間の関係を表すグラフに関わる計算上の問題である。次のようなものがある。
• traversal, or the problem of exploring all the vertices in a graph
英語のヒント
・走査。グラフ内のすべての頂点を調べる問題。
• minimum spanning tree is the problem of finding a lowest-cost way to connect all the vertices to each other
英語のヒント
・最小全域木。すべての頂点を互いに接続する、最小コストの方法を見つける問題。
• shortest path is the problem of finding the lowest-cost way to get from one vertex to another
・最短経路。ある頂点から別の頂点へ移動する、最小コストの方法を見つける問題。
A string problem is a computational problem involving text or information represented as a sequence of characters. Examples include:
文字列の問題とは、文字の列として表されたテキストや情報に関わる計算上の問題である。次のような例がある。
• matching, or the problem of searching for a text pattern within a document
英語のヒント
・照合。文書内で、あるテキストのパターンを探す問題。
• compression, or the problem of representing information using less data storage
英語のヒント
・圧縮。データの記憶領域をより少なく使って情報を表す問題。
• cryptography, or the problem of masking or obfuscating text to make it unintelligible
英語のヒント
・暗号。テキストを隠したり難読化したりして、理解できなくする問題。
Modelingモデル化
Computer scientists focus on defining a problem model, often simply called a model, which is a simplified, abstract representation of more complex real-world problems. They apply the algorithmic problem-solving process mentioned previously to design algorithms when defining models. Algorithms model phenomena in the same way that data structures implement abstract data types such as lists, sets, maps, priority queues, and graphs. But unlike abstract data types, models are not necessarily purely abstract or mathematical concepts. Models are often linked to humans and social phenomena. A medical system might want to decide which drugs to administer to which patients, so the algorithm designer might decide to model patients as a complex data type consisting of age, sex, weight, or other physical characteristics. Because models represent abstractions, or simplifications of real phenomena, a model must emphasize some details over others. In the case of the medical system, the algorithm designer emphasized physical characteristics of people that were deemed important and chose to ignore other characteristics, such as political views, which were deemed less important for the model.
英語のヒント
コンピューター科学者は、問題モデルを定義することを重視する。これは単にモデルとも呼ばれ、現実世界のより複雑な問題を単純化し、抽象的に表現したものである。モデルを定義する際には、前述のアルゴリズムによる問題解決の過程を使い、アルゴリズムを設計する。データ構造がリスト、集合、マップ、優先度付きキュー、グラフなどの抽象データ型を実装するのと同じように、アルゴリズムは現象をモデル化する。しかし、抽象データ型とは異なり、モデルは必ずしも純粋に抽象的、あるいは数学的な概念ではない。人間や社会現象に結び付いていることも多い。医療システムでは、どの患者にどの薬を投与するかを決めたいかもしれない。その場合、アルゴリズムの設計者は、年齢、性別、体重、その他の身体的特徴からなる複雑なデータ型として、患者をモデル化することにするかもしれない。モデルは現実の現象を抽象化、つまり単純化したものなので、ある詳細をほかの詳細より重視せざるを得ない。医療システムの例では、アルゴリズムの設計者は、人々の身体的特徴を重要とみなして重視し、政治的見解などのほかの特徴は、モデルにとって重要性が低いとみなして無視することを選んだ。
If an algorithm is a solution to a problem, then the model is the frame through which the algorithm designer defines the rules and potential outcomes. Without models, algorithm designers would struggle with the infinite complexity and richness of the world. Imagine, for example, designing a medical system that models patients at the level of individual atoms. This model offers a detailed representation of each patient in the most physical or literal sense. But this model is impractical because we do not know how particular configurations and collections of atoms contribute to a person’s overall health. Compared to this atomic-scale model, our former model consisting of age, sex, weight, and other physical characteristics is more practical for designing algorithms, but necessarily involves erasing our individual humanity to draw certain conclusions.
英語のヒント
アルゴリズムが問題の解であるなら、モデルは、アルゴリズムの設計者が規則と起こり得る結果を定義するための枠組みである。モデルがなければ、設計者は世界の限りない複雑さと豊かさに苦しむことになる。たとえば、患者を個々の原子の水準でモデル化する医療システムを設計するとしよう。このモデルは、最も物理的、あるいは文字どおりの意味で、患者一人ひとりを詳細に表す。しかし、原子の特定の配置や集まりが、その人の健康全体にどう関わるかわからないため、このモデルは実用的でない。原子規模のモデルと比べると、先ほどの年齢、性別、体重、その他の身体的特徴からなるモデルのほうが、アルゴリズムの設計には実用的である。しかし、ある結論を導くために、私たちそれぞれの人間性をそぎ落とすことが必然的に伴う。
In order to design algorithms, we need to be able to focus on relevant information rather than detailed representations of the real world. Further, computer science requires a philosophical mind to aid in problem solving. According to Brian Cantwell Smith, philosopher and cognitive and computer scientist, “Though this is not the place for metaphysics, it would not be too much to say that every act of conceptualization, analysis, or categorization, does a certain amount of violence to its subject matter, in order to get at the underlying regularities that group things together.”1 Without performing this “violence,” there would be too many details to wade through to create a useful algorithm.
英語のヒント
アルゴリズムを設計するには、現実世界の詳細な表現よりも、関連する情報に注目できなければならない。さらに、コンピューターサイエンスで問題解決を助けるには、哲学的な思考が必要である。哲学者、認知科学者、コンピューター科学者であるブライアン・キャントウェル・スミスは、次のように述べる。「ここは形而上学を論じる場ではないが、概念化、分析、分類という行為はどれも、物事をひとまとまりにする根底の規則性を捉えるために、その対象にある程度の暴力を加える、と言っても言い過ぎではない。」1この「暴力」を加えなければ、有用なアルゴリズムを作るために、あまりにも多くの細部をかき分けなければならなくなる。
The relationship between algorithms, the software they empower, and the social outcomes they produce is currently the center of contested social and political debate. For example, all media platforms (e.g., Netflix, Hulu, and others) use some level of targeted advertising based on user preferences in order to recommend specific movies or shows to their users. Users may not want their information to be used in this way, but there must be some degree of compromise to make these platforms attractive and useful to people.
英語のヒント
アルゴリズム、それによって動くソフトウェア、そしてそれらが生み出す社会的な結果の関係は、現在、社会的・政治的な論争の中心にある。たとえば、NetflixやHuluなど、すべてのメディアプラットフォームは、利用者に特定の映画や番組を推薦するために、利用者の好みに基づいたターゲット広告を何らかの水準で使っている。利用者はこのように自分の情報を使われたくないかもしれないが、プラットフォームを人々にとって魅力的で便利なものにするには、ある程度の折り合いが必要になる。
1 B. C. Smith, “The limits of correctness.” ACM SIGCAS Comput. Soc., vol. 14, 15, no. 1, 2, 3, 4, pp. 18-26, Jan. 1985. https://doi.org/ 10.1145/379486.379512.
1 B. C. Smith「The limits of correctness(正しさの限界)」ACM SIGCAS Comput. Soc.、第14・15巻、第1・2・3・4号、18–26頁、1985年1月。https://doi.org/ 10.1145/379486.379512。
On the one hand, the technical definition of an algorithm is that it represents complex processes as a sequence of precise instructions operating on data. This definition does not overtly suggest how algorithms encode social outcomes. On the other hand, computer programs are human-designed and socially engineered. Algorithm designers simplify complex real-world problems by removing details so that they can be modeled as computational problems. Because software encodes and automates human ideas with computers, software engineers wield immense power through their algorithms.
英語のヒント
一方では、アルゴリズムの技術的な定義は、複雑な過程を、データに作用する正確な指示の列として表すもの、ということである。この定義からは、アルゴリズムが社会的な結果をどのように組み込むかは明示的にはわからない。他方、コンピュータープログラムは人間が設計し、社会的に作り上げたものである。アルゴリズムの設計者は、現実世界の複雑な問題から細部を取り除いて単純化し、計算上の問題としてモデル化できるようにする。ソフトウェアは人間の考えをコンピューターに組み込み、自動化するため、ソフトウェア技術者は、自らのアルゴリズムを通じて巨大な力を振るう。
To further complicate the matter, software engineering is often a restrictive and formal discipline. Problem modeling is constrained by the model of computation, or the rules of the underlying computer that is ultimately responsible for executing the algorithm. Historically, computer science grew from its foundations in mathematics and formal logics, so algorithms were specialized to solve specific problems with a modest model of the underlying phenomena. This approach to algorithm design solves certain types of problems so long as they can be reasonably reduced to models that operate on a modest number of variables—however many variables the algorithm designer can keep in mind. In the case of the medical system, the algorithm designer identified certain characteristics as particularly useful for computing a result.
英語のヒント
さらに話を複雑にするのは、ソフトウェア工学がしばしば制約の厳しい形式的な学問分野だという点である。問題のモデル化は、計算モデル、すなわち最終的にアルゴリズムを実行するコンピューターの根本的な規則によって制約される。歴史的に、コンピューターサイエンスは数学と形式論理を基礎に発展した。そのためアルゴリズムは、背後の現象を比較的小規模に表したモデルを使い、特定の問題を解くように特化してきた。このようなアルゴリズム設計の方法では、問題を適切に、比較的少数の変数、つまり設計者が頭に置いておける数の変数を扱うモデルへ落とし込める限り、ある種類の問題を解ける。医療システムの例では、設計者は、結果の計算に特に有用な特徴を選び出した。
But there are many other problems that defy this approach, particularly tasks that involve subtle and often unconscious use of human sensory and cognitive faculties. An example of this is facial recognition. If asked to describe how we recognize a particular person’s face, an algorithm designer would be challenged to identify specific variables or combinations of variables that correspond to only a single person. The formal logic required to define an algorithm is strict and absolute, whereas our understanding human faces is defined by many subtle factors that are difficult for anyone to express using formal logic.
英語のヒント
しかし、この方法では扱いきれない問題も多い。特に、人間の感覚や認知能力を、微妙な形で、多くの場合は無意識に使う作業がそうである。一例が顔認識である。ある人の顔をどう見分けるかを説明するよう求められたら、アルゴリズムの設計者は、その1人だけに対応する具体的な変数や変数の組合せを特定するのに苦労するだろう。アルゴリズムの定義に必要な形式論理は厳密で絶対的である。それに対し、人間の顔についての私たちの理解は、形式論理では誰にとっても表しにくい、多くの微妙な要因によって決まる。