markdown
グラフの基本md 74b4241
lecture/information/graph/graph-basics.lecture.n.md
Download PDF

グラフの基本きほん

date2026-07-14document_iddoc_7e6024074b2e40e0772916eed50e48d0description対象間の関係を頂点と辺で表すグラフの定義、隣接、道、距離、連結性を整理し、探索アルゴリズムの前提を構成する。prerequisites集合の基本 / 写像と関係の基本type講義statusactiverelateddata/lecture/information/discrete-math/sets-and-maps-basics.lecture.n.md / data/lecture/information/algorithm/search/dfs-and-bfs-basics.lecture.n.md
informationgraphundergraduatelecture

1導入どうにゅう

この講義こうぎでは、対象間たいしょうかんの関係かんけいを頂点ちょうてんと辺へんで表あらわすグラフの定義ていぎと、探索たんさくを記述きじゅつするために必要ひつような隣接りんせつ・道みち・距離きょり・連結性れんけつせいを説明せつめいする。

道路網どうろもうでは交差点こうさてんの形かたちより接続関係せつぞくかんけいが重要じゅうようであり、通信網つうしんもうでは機器ききの外観がいかんより通信可能性つうしんかのうせいが重要じゅうようである。グラフは、対象たいしょうそのものから関係かんけいだけを抽出ちゅうしゅつし、異ことなる問題もんだいを同おなじ構造こうぞうとして扱あつかうための表現ひょうげんである。

2用語ようごと定義ていぎ

グラフ G=(V,E) は、頂点ちょうてんの集合しゅうごう V と辺へんの集合しゅうごう E からなる。頂点ちょうてんは対象たいしょうを、辺へんは二ふたつの対象間たいしょうかんの関係かんけいを表あらわす。この講義こうぎの無向むこうグラフは有限単純ゆうげんたんじゅんグラフであり、

E⊆{{u,v}⊆V∣u≠v}

とする。したがって、自己じこループと多重辺たじゅうへんは含ふくまれない。

有向ゆうこうグラフでは E⊆V×V とし、辺へん (u,v) は u から v への向むきを持もつ。以下いかでは、特とくに断ことわらない限かぎり有限単純無向ゆうげんたんじゅんむこうグラフを扱あつかう。

二頂点にちょうてん u,v が辺へんで直接結ちょくせつむすばれているとき、u と v は隣接りんせつするという。頂点ちょうてん v に隣接りんせつする頂点ちょうてんの集合しゅうごうを

N(v)={u∈V∣{u,v}∈E}

と書かく。

3道みちと距離きょり

頂点列ちょうてんれつ

v0,v1,…,vk

が各かく i=1,…,k について {vi-1,vi}∈E を満みたすとき、この列れつを長ながさ k の歩道ほどうという。さらに v0,…,vk が相異あいことなるとき、これを道みちという。頂点ちょうてん s から v への歩道ほどうが存在そんざいするとき、閉路へいろを除のぞけば道みちが得えられるため、v は s から到達可能とうたつかのうである。

無重むおもみグラフにおける距離きょり d(s,v) は、s から v への道みちの長ながさの最小値さいしょうちである。道みちが存在そんざいしない場合ばあいは d(s,v)=∞ とする。ここで「無重むおもみ」とは、すべての辺へんを一歩いっぽとして数かぞえることを意味いみする。

4連結性れんけつせい

任意にんいの二頂点にちょうてんの間あいだに道みちが存在そんざいする無向むこうグラフを連結れんけつという。連結れんけつでないグラフは、互たがいに到達可能とうたつかのうな頂点ちょうてんをまとめた連結成分れんけつせいぶんに分解ぶんかいできる。

例れいえば

V={a,b,c,d},E={{a,b},{b,c}}

では、a,b,c は同おなじ連結成分れんけつせいぶんに属ぞくし、d は単独たんどくの連結成分れんけつせいぶんをなす。また、d(a,c)=2 である。

5表現方法ひょうげんほうほう

隣接りんせつリストは各頂点かくちょうてん v に対たいして N(v) を保存ほぞんする。頂点数ちょうてんすうを |V|、辺数へんすうを |E| とすると、無向むこうグラフの全隣接ぜんりんせつリストの要素数ようそすうは 2|E| である。各辺かくへんが両端点りょうたんてんのリストに一度いちどずつ現あらわれるためである。

隣接行列りんせつぎょうれつは、頂点ちょうてんに番号ばんごうを付つけ、辺へんの有無うむを行列要素ぎょうれつようそで表あらわす。辺へんの存在判定そんざいはんていは高速こうそくだが、頂点数ちょうてんすうの二乗にじょうに比例ひれいする領域りょういきを必要ひつようとする。疎そなグラフでは隣接りんせつリストが適てきし、密みつなグラフや辺へんの存在判定そんざいはんていを頻繁ひんぱんに行おこなう場合ばあいは隣接行列りんせつぎょうれつが候補こうほになる。

6探索たんさくへの接続せつぞく

グラフ探索たんさくは、始点してんから隣接頂点りんせつちょうてんを順じゅんに調しらべ、到達可能とうたつかのうな頂点ちょうてんを列挙れっきょする操作そうさである。この講義こうぎで定義ていぎした頂点ちょうてん、辺へん、隣接りんせつ、道みち、距離きょりが、DFSとBFSの入力にゅうりょくと主張しゅちょうを構成こうせいする。

data/lecture/information/algorithm/search/dfs-and-bfs-basics.lecture.n.md

7まとめ

data/exercise/information/algorithm/search/graph-traversal-and-unweighted-distance.exercise.n.md
  • グラフ G=(V,E) は、対象たいしょうを頂点ちょうてん、関係かんけいを辺へんとして表あらわす。
  • 道みちは相異あいことなる隣接頂点りんせつちょうてんを順じゅんに並ならべた列れつであり、無重むおもみ距離きょりは最短さいたんの道みちの辺数へんすうである。
  • 連結性れんけつせいは、任意にんいの二頂点間にちょうてんかんの到達可能性とうたつかのうせいで定義ていぎされる。
  • 隣接りんせつリストと隣接行列りんせつぎょうれつは、同おなじグラフを異ことなる計算特性けいさんとくせいで表現ひょうげんする。

Graph Basics

1Introduction

This lecture defines graphs as representations of relationships between objects and develops adjacency, paths, distance, and connectivity as the concepts required for graph traversal.

In a road network, connectivity matters more than the shapes of intersections. In a communication network, reachability matters more than the appearance of devices. A graph extracts these relationships and allows structurally identical questions to be treated in a common language.

2Terms and definitions

A graph G=(V,E) consists of a set V of vertices and a set E of edges. Vertices represent objects, while edges represent relationships between pairs of objects. An undirected graph in this lecture is a finite simple graph with

E⊆{{u,v}⊆V∣u≠v}.

Thus it contains neither self-loops nor parallel edges.

For a directed graph, E⊆V×V, and an edge (u,v) is oriented from u to v. Unless stated otherwise, the remainder of this lecture considers finite simple undirected graphs.

Two vertices u,v are adjacent when an edge directly joins them. The neighborhood of a vertex v is

N(v)={u∈V∣{u,v}∈E}.

3Paths and distance

A sequence of vertices

v0,v1,…,vk

is a walk of length k when {vi-1,vi}∈E for every i=1,…,k. It is a path when v0,…,vk are distinct. If a walk from s to v exists, deleting cycles yields a path, and v is reachable from s.

In an unweighted graph, the distance d(s,v) is the minimum length of a path from s to v. If no path exists, set d(s,v)=∞. Here, “unweighted” means that every edge counts as one step.

4Connectivity

An undirected graph is connected when a path exists between every pair of vertices. A disconnected graph decomposes into connected components, each consisting of vertices that are mutually reachable.

For example, if

V={a,b,c,d},E={{a,b},{b,c}},

then a,b,c form one connected component, while d forms a component by itself. Moreover, d(a,c)=2.

5Representations

An adjacency list stores N(v) for each vertex v. If the graph has |V| vertices and |E| edges, all adjacency lists of an undirected graph contain 2|E| entries in total, because every edge appears once at each endpoint.

An adjacency matrix numbers the vertices and records edge existence in matrix entries. It supports fast edge-existence queries but requires space proportional to the square of the number of vertices. Adjacency lists are suitable for sparse graphs; adjacency matrices are candidates for dense graphs or workloads dominated by edge-existence queries.

6Connection to traversal

A graph traversal starts at a vertex, examines adjacent vertices in a specified order, and enumerates reachable vertices. Vertices, edges, adjacency, paths, and distance as defined here form the input and claims of DFS and BFS.

data/lecture/information/algorithm/search/dfs-and-bfs-basics.lecture.n.md

7Summary

data/exercise/information/algorithm/search/graph-traversal-and-unweighted-distance.exercise.n.md
  • A graph G=(V,E) represents objects as vertices and relationships as edges.
  • A path is a sequence of distinct adjacent vertices, and unweighted distance is the number of edges in a shortest path.
  • Connectivity is defined by reachability between every pair of vertices.
  • Adjacency lists and adjacency matrices represent the same graph with different computational tradeoffs.
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる