第3章データ構造とアルゴリズム
CONCEPTS IN PRACTICE概念を実践する
Tracking Earthquakes地震を追跡する
Earthquakes, hurricanes, tsunamis, and other natural disasters occur regularly, and often demand an international response. How do we track natural disasters and identify the most affected areas in order to coordinate relief and support efforts? In the United States, the U.S. Geological Survey (USGS) is responsible for reporting earthquakes using thousands of earthquake sensors. However, that still leaves many places without earthquake sensors. Outside the United States, sensor technology may be less robust or inaccessible.
英語のヒント
地震、ハリケーン、津波などの自然災害は繰り返し発生し、国際的な対応を必要とすることも多い。救援や支援の取り組みを連携させるには、どうやって自然災害を追跡し、最も被害の大きい地域を見つければよいだろうか。米国では、米国地質調査所(USGS)が数千個の地震センサーを使い、地震の報告を担当している。しかし、それでも地震センサーのない場所は数多く残る。米国外では、センサー技術の信頼性が低かったり、利用できなかったりすることもある。
Social network data can be used to enhance this information and more quickly alert governments about natural disasters in real-time. By monitoring public social network platforms for occurrences of short posts such as “earthquake?,” we can quickly localize earthquakes based on the user’s geolocation data. However, aggregating and understanding this data—often thousands of data points arriving in minutes—requires efficient data structures and algorithms. We can use a binary heap that implements the priority queue abstract data type for an earthquake-tracking program. For each “earthquake?” post received for a given geolocation, we can increase the priority of the earthquake locations, which helps identify the likely-earthquake location that is closest to the user’s real location. At any time, we can efficiently retrieve the highest-priority element from the priority queue. By choosing to use a binary heap rather than a linear data structure for implementing the priority queue, we can ensure that the earthquake-tracking program is able to keep up with the thousands of posts made every minute during an earthquake.
英語のヒント
ソーシャルネットワークのデータを使えば、この情報を補強し、自然災害をリアルタイムで、より早く政府へ知らせることができる。公開されたソーシャルネットワーク上で「地震?」のような短い投稿を監視すると、利用者の位置情報から、地震の場所を素早く特定できる。しかし、数分で数千件も届くことがあるこうしたデータを集約し、理解するには、効率のよいデータ構造とアルゴリズムが必要である。地震追跡プログラムには、優先度付きキューの抽象データ型を実装する二分ヒープを使える。ある位置から届く「地震?」という投稿ごとに、地震の場所の優先度を上げられる。これにより、利用者の実際の場所に最も近い、地震が起きた可能性の高い場所を特定しやすくなる。いつでも優先度付きキューから、優先度の最も高い要素を効率よく取得できる。優先度付きキューの実装に線形データ構造ではなく二分ヒープを選べば、地震中に毎分数千件も行われる投稿に、地震追跡プログラムが追い付けるようにできる。
Graph Data Structuresグラフのデータ構造
Both binary search trees and binary heap data structures represent more efficient ways to implement sets, maps, and priority queues by organizing data according to their intrinsic properties. In both cases, the properties of data enable efficient addition, retrieval, and removal of elements.
英語のヒント
二分探索木と二分ヒープのデータ構造はどちらも、データに内在する性質に従ってデータを整理することで、集合、マップ、優先度付きキューをより効率よく実装する方法である。どちらの場合も、データの性質によって、要素を効率よく追加、取得、削除できる。
Graphs are a different kind of abstract data type. Rather than focusing on addition, retrieval, and removal, graphs focus on explicitly modeling the relationships between elements. Graphs afford access not only to elements, but also to relationships between elements.
英語のヒント
グラフは、それらとは異なる種類の抽象データ型である。追加、取得、削除に重点を置くのではなく、要素間の関係を明示的にモデル化することに重点を置く。グラフでは、要素だけでなく、要素間の関係にもアクセスできる。
• A vertex represents an element in a graph or a special type of it, such as a tree.
・頂点は、グラフ、または木のようなグラフの特殊な種類における要素を表す。
• An edge is the relationship between vertices or nodes. Optionally, edges can have associated weights. In a graph abstract data type, the relationships between two vertices connected by an edge are considered adjacent.
英語のヒント
・辺は、頂点やノードの間の関係である。必要に応じて、辺には重みを対応させられる。グラフ抽象データ型では、辺で結ばれた2つの頂点の関係を隣接とみなす。
LINK TO LEARNING学習リンク
Visualgo is a website that provides animations to help users learn more about algorithms and data structures. They have exercises to help understand several concepts presented in this chapter. You can access animations on various data structures and algorithms (https://openstax.org/r/76Visualgo) such as a linked list, a binary search tree, and graph structures.
Visualgoは、アルゴリズムやデータ構造をさらに学ぶためのアニメーションを提供するウェブサイトである。この章で紹介するいくつかの概念の理解を助ける演習もある。連結リスト、二分探索木、グラフ構造など、さまざまなデータ構造とアルゴリズムのアニメーション(https://openstax.org/r/76Visualgo)を利用できる。
In computer networks such as the Internet, graphs can represent individual network routers as nodes with data packets flowing between directly connected routers along edges. Even though not every router is directly connected to every other router, the router at the current node can analyze an incoming data packet to determine which edge it should travel through next. By repeating this process, a data packet can travel from a router on the Internet to another router on the Internet even though the two routers are not directly adjacent to each other.
英語のヒント
インターネットのようなコンピューターネットワークでは、グラフのノードで個々のネットワークルーターを表し、辺に沿って、直接接続されたルーター間をデータパケットが流れるように表せる。すべてのルーターがほかのすべてのルーターへ直接接続されているわけではないが、現在のノードにあるルーターは、到着したデータパケットを分析し、次にどの辺を通らせるかを決定できる。この処理を繰り返すことで、2つのルーターが直接隣接していなくても、データパケットはインターネット上の一方のルーターから、もう一方のルーターまで移動できる。
Graphs are unique in that they can directly represent a wide variety of real-world problems, such as the following:
英語のヒント
グラフが特徴的なのは、次のような多様な現実世界の問題を、直接表現できる点である。
• A social network, where each vertex is a person, and each edge is a friendship.
・ソーシャルネットワーク。各頂点が人を、各辺が友人関係を表す。
• The Web, where each vertex is a webpage, and each edge is a link.
・ウェブ。各頂点がウェブページを、各辺がリンクを表す。
• A campus map, where each vertex is a building, and each edge is a footpath.
英語のヒント
・キャンパスの地図。各頂点が建物を、各辺が歩道を表す。
• A course prerequisite diagram, where each vertex is a course, and each edge is a prerequisite.
英語のヒント
・科目の履修条件を示す図。各頂点が科目を、各辺が履修の前提条件を表す。
Unlike the list, set, map, and priority queue abstract data types, which have relatively standardized functionality focusing on the addition, retrieval, and removal of elements, the graph abstract data type is much less standardized. Typically, graph algorithm designers will create their own graph data type to represent a problem. The corresponding graph problem can then be represented using or adapting a standard graph algorithm. Unlike programming with other abstract data types, much of the hard work of solving a problem with a graph occurs when programmers decide what the vertices and edges represent, and which graph algorithm would be appropriate to solve the problem. They also must consider the consequences of how they represent the problem.
英語のヒント
リスト、集合、マップ、優先度付きキューの抽象データ型は、要素の追加、取得、削除を中心とする機能が比較的標準化されている。それらと違い、グラフ抽象データ型の標準化の程度は、はるかに低い。グラフのアルゴリズムの設計者は通常、問題を表すために独自のグラフデータ型を作る。そのグラフの問題は、標準的なグラフアルゴリズムをそのまま使ったり、調整したりして表せる。ほかの抽象データ型を使うプログラミングと異なり、グラフで問題を解く際の難しい作業の多くは、頂点と辺に何を表させるか、問題の解決にどのグラフアルゴリズムが適するかを決める段階にある。問題の表し方がもたらす結果も考慮しなければならない。