• 検索結果がありません。

Algorithms 実践的アルゴリズ ム理論

N/A
N/A
Protected

Academic year: 2021

シェア "Algorithms 実践的アルゴリズ ム理論"

Copied!
20
0
0

読み込み中.... (全文を見る)

全文

(1)

実践的アルゴリズム理論 Theory of Advanced

Algorithms

グラフのデータ構造 担当:上原隆平

(2)

Theory of Advanced

Algorithms 実践的アルゴリズ ム理論

Data Structure of Graphs

Ryuhei Uehara

(3)

新宿

東京 池袋 上野

例: 講義の履修順序

グラフ (graph)

頂点を辺で結んだもの

有向グラフ

:

辺に方向がある

無向グラフ

:

辺に方向がない

例: 路線図

(4)

• Vertices are joined by edges

– Directed graph: each edge has direction

– (Undirected) graph: each edge has no direction

Shinjuku

Tokyo Ikebukuro Ueno

Example: Order of classes

Graph

Example: Railmap

(5)

グラフ : 表記

u1

u2 u10

u3

u4

u9

u7 u5 u6

u8

東京 上野 新宿 池袋

グラフ

: G = (V, E)

V:

頂点集合,

E:

辺集合

頂点

: u, v, … ∈ V

: e = {u, v} ∈ E

(無向辺)

a = (u, v) ∈ E

(有向辺)

頂点や辺は重みを持つことも

w(u), w(e)

距離,金額,時間など

5

(6)

• Graph: G = (V, E)

V: Vertex set

E: Edge set

• Vertices: u, v, … ∈ V

• Edges: e = {u, v} ∈ E (undirected) a = (u, v) ∈ E (directed)

• Vertices/edges can have weight

w(u), w(e)

– Distance, price, time, etc.

Graph: Notation

u1

u2 u10

u3

u4

u9

u7 u5 u6

u8

Tokyo Ueno Ikebukuro

Shinjuku

6

(7)

グラフ : 基本的な用語 (1/2)

(path):

辺で隣り合う頂点を繋いだもの

単純路

(simple path):

同じ頂点を複数回通らない

閉路

(cycle, closed path): v

から

v

への路

連結グラフ

(connected graph):

どの

2

頂点間 にも路が存在するグラフ

(8)

Graph: Basic terms (1/2)

• Path: Vertices joined by edges

– Simple path: never visits the same vertex twice

• cycle, closed path: path from v to v

• connected graph: Any pair of vertices is

joined by a path

(9)

グラフ : 基本的な用語 (2/2)

(forest):

閉路を含まないグラフ

(tree):

連結で閉路を含まないグラフ

平面的グラフ

(planar graph):

辺の交差なし で平面に描画できるグラフ

完全グラフ

(complete graph):

全ての頂点対 を辺で隣接させたグラフ

完全グラフ

K

5 は極小非平面的グラフ

(10)

Graph: Basic terms (2/2)

• forest: acyclic graph (no cycle)

• tree: connected acyclic graph

• planar graph: It can be drawn on a plane without crossing of edges

• complete graph: graph s. t. all pairs are joined

– Complete graph K

5

is

a minimal non-planar graph

(11)

グラフアルゴリズムの計算量

頂点数

n,

辺数

m ∈ O(n

2

)

無向グラフ

: m ≦ n(n-1)/2

有向グラフ

: m ≦ n(n-1)

平面グラフでは

m ∈ O(n)

グラフアルゴリズムの計算量は

n

m

の式で表す

(12)

Complexity of graph algorithms

n vertices and m edges; m ∈ O(n

2

)

– undirected graph: m ≦ n(n-1)/2 – directed graph: m ≦ n(n-1)

• On a plane graph, m ∈ O(n)

• Computational complexity of a graph

algorithm is given by an expression of n,m

(13)

グラフの表現方法

隣接行列

隣接リスト

1 2 3

4 4

2 3

4 2

頂点 隣接頂点のリスト

1 2

3

4

13

(14)

Representation of a graph

• Adjacency matrix

• Adjacency list

1 2 3

4 4

2 3

4 2

Vertices List of neighbors

1 2

3

4

14

(15)

1 2

3

4

グラフの表現方法 : 行列表現(隣接行列)

• (u, v) ∈ EM[u, v] = 1

• (u, v) EM[u, v] = 0

(16)

1 2

3

4

Representation of a graph:

Matrix representation (adj. matrix)

• (u, v) ∈ EM[u, v] = 1

• (u, v) EM[u, v] = 0

(17)

1 2 3

4 4

2 3

4 2

頂点 隣接頂点のリスト

グラフの表現方法 : リスト表現(隣接リスト)

1 2

3

4

• (u, v) ∈ EvT(u)

T(u)

u

の隣接点のリスト

:

(18)

• (u, v) ∈ EvT(u)

T(u) is the list of neighbors of u

• Example:

1 2 3

4 4

2 3

4 2

Vertices List of neighbors

Representation of a graph:

List representation (adj. list)

1 2

3

4

(19)

隣接行列 vs 隣接リスト

メモリ量

隣接行列

: Θ(n

2

)

隣接リスト

: Θ(m log n)

隣接チェックにかかる時間

: (u, v) ∈ E ?

隣接行列

: Θ(1)

隣接リスト

: Θ(n)

(20)

• Memory

– Adj. matrix: Θ(n

2

) – Adj. list: Θ(m log n)

• Time for check if (u, v) ∈ E ?

– Adj. matrix: Θ(1) – Adj. list: Θ(n)

Adj. Matrix vs Adj. List

参照

関連したドキュメント

modular proof of soundness using U-simulations.. & RIMS, Kyoto U.). Equivalence

The layout produced by the VDCB algorithm is more evenly distributed according to the CP model, and is more similar to the original layout according to the similarity measures

The dynamic nature of our drawing algorithm relies on the fact that at any time, a free port on any vertex may safely be connected to a free port of any other vertex without

It is thus often the case that the splitting surface of a strongly irreducible Heegaard splitting of a graph manifold can’t be isotoped to be horizontal or pseudohorizontal in

Additionally, the set of limiting densities of minor-closed graph families is the closure of the set of densities of a certain family of finite graphs, the density- minimal graphs

The planarization of a simple arrangement of curves is the planar graph whose vertices are crossing points of pairs of curves, and whose edges are pairs of vertices that are

Each graph in subset Small-graphs was generated by the following procedure: (i) Generate, with a uniform probability distribution, a connected (possibly non-planar) graph hav- ing

Theorem 5.1 Let G be a connected regular graph with four distinct eigenvalues. Then G is one of the relations of a 3-class association scheme if and only if any two adjacent