Date post: | 06-Jan-2018 |
Category: |
Documents |
Upload: | abner-jefferson |
View: | 232 times |
Download: | 0 times |
Chapter 11. Graphs
Internet Computing Laboratory @ KUT
Youn-Hee Han
Where We Are?
Tree Binary Tree Binary Search Tree AVL Search Tree
Heap
Multiway Trees
Graph
1. Basic ConceptsGraph
a collection of nodes (vertices) and lines (edges, arcs) The lines in a graph are called
Undirected graphs: edge Directed graphs (Digraph): arc
edge arc
1. Basic ConceptsFirst use of graphs: Köenigsberg bridge problem [Leonhard Euler 1736]
Starting from land area, is it possible to return to starting location after walking across each of the bridges exactly once?
Eulerian walk is possible if and only if the degree of each vertex is even
C
B
A Da b
dc
f
g
e
1. Basic ConceptsExamples of Graph
0
6543
21
0
1 2
3
G1 G2
V(G2)={0,1,2,3,4,5,6}E(G2)={(0,1), (0,2), (1,3), (1,4), (2,5), (3,6)}
V(G1)={0,1,2,3} E(G1)={(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)}
1. Basic ConceptsTerminologies
Path: sequence of vertices in which each vertex is adjacent to next one
Ex) ABCE, ABEF in Figure (a) Ex) ABCE, ECBA, ABEF, FEBA in Figure (b)
Two vertices are adjacent (or neighbors) if there is a path connecting them
The vertices share a path of length 1 connecting them. B is adjacent to A D is not adjacent to F
Data Structure6(a) (b)
1. Basic ConceptsTerminologies
Cycle: a path whose start and end vertices are the same
In figure (a), B,C,D,E,B is not cycle In figure (b), B,C,D,E,B is cycle
Cyclic Graph is a graph with a cycle Loop: single arc begins and ends at the same vertex
Data Structure7
(a) (b) (c)
1. Basic ConceptsTerminologies
Two vertices are connected if there is a path between them
A graph is connected if there is a path from any vertex to any other vertex, ignoring direction
Directed graph… It is strongly connected if there is a path from each vertex to
every other vertex, considering direction Otherwse, it is weakly connected
Undirected graph is always stong connected if it is connected
A graph is disjoint if it is not connected
Data Structure8
1. Basic ConceptsTerminologies
Connected Graph - (a), (b), (d), (e), (f) Disjoint Graph – (c) Complete Graph ( 완전 그래프 ) – (e), (f)
모든 Node 들 간에 1:1 로 직접 연결된 Edge 를 지닌 그래프 모든 Node 들이 서로 인접 (Adjacent) 하다 . a graph that has the maximum # of edges
0
1 2
3(f)
Data Structure9
1. Basic ConceptsTerminologies
G’(V’,E’) is subgraph of G(V, E) V(G ’) V(G ) and E(G ’) E(G )
Subgraph G’ 는 그래프 G 의 일부 Node 들과 이들을 연결하는 Edge 만을 취하여 만든 부분 그래프
G1 subgraphs of G1
Data Structure10
1. Basic ConceptsTerminologies
The degree of a vertex is the number of lines incident to it.
In Figure (a), the degree of vertex B is 3 and the degree of vertex E is 4
The outdgree and indegree of a vertex In Figure (a), the indegree of vertex B is 1 and its
outdegree is 2 In Figure (b), the indegree of vertex E is 3 and its
outdegree is 1
Data Structure11
1. Basic ConceptsTerminologies
그래프의 동일성 아래 두 그래프는 동일하다 (or 일치한다 ) = homogeneous
Node 들 상호간의 공간적인 위치 관계 (Topology) 는 중요하지 않다 같은 Node 집합을 지니고 있고 그들 사이에 Edge 연결 상태가 동일하면
두 그래프는 일치한다 .
Data Structure12
Data Structure13
1. Basic Concepts그래프와 트리
Tree 연결된 (Connected) & 사이클 없는 (Acyclic) 그래프 V 개의 정점 , 항상 V-1 개의 간선 a graph in which any two vertices are connected by exactly one path
Data Structure14
1. Basic Concepts그래프와 트리
V 개의 Node 들에 대하여 V-1 개 보다 많은 Edge 가 존재하면 사이클이 존재 (Cyclic Graph) V-1 보다 적으면 절단 그래프 (Disjoint Graph)
2. OperationsInserting a vertex
Deleting a vertex
Data Structure15
2. OperationsInserting an edge
Deleting an edge
Data Structure16
2. OperationsTraverse
Depth-first traversal – Goal Seeking process all of a vertex’s descendents before we move to
an adjacent vertex Use Stack!!!
Data Structure17
2. OperationsTraverse
Depth-first traversal – Just Traverse All Vertex process all of a vertex’s descendents before we move to
an adjacent vertex Use Stack!!! (After Push…, Pop and Process)
Data Structure18
2. OperationsTraverse
Breadth-first traversal – Just Traverse All Vertex process all adjacent vertices of a vertex before going to
the next level Use Queue!!!
Data Structure19
3. Graph Storage StructuresAdjacency Matrix ( 인접 행렬 )
A vector (one-dimensional array) for a vertices and a matrix to store the edges
2 차원 행렬 : 2 차원 배열 - A[MAX][MAX] 직접 연결된 간선이 있으면 해당 값을 1(True)
Data Structure20
일종의 심볼 테이블
3. Graph Storage StructuresAdjacency Matrix ( 인접 행렬 )
무방향 그래프 (Undirected Graph) 인 경우 무방향 그래프의 인접행렬은 대각선을 중심으로 대칭 메모리 절약을 위해 배열의 반쪽 만을 사용할 수 있음
방향 그래프 (Directed Graph) 인 경우 대칭이 아님
Data Structure21
일종의 심볼 테이블
3. Graph Storage StructuresAdjacency Matrix ( 인접 행렬 )
인접행렬 표현을 위한 심볼 테이블 Node ID 를 배열 인덱스로 매핑 시키는 테이블 “a 에서 c 로 가는 Direct Edge 가 있는가 ?”
a 0 e 4 A[0][4] 가 1 이면 a 와 e 는 edge 존재
Data Structure22
Vertex 배열 인덱스
a 0b 1c 2d 3e 4
3. Graph Storage StructuresAdjacency List ( 인접 리스트 )
2-dimensional ragged ( 울퉁불퉁한 ) array to store the edges
Vertext list A singly linked list of the vertices in the list.
하나의 정점에 인접한 모든 노드를 연결 리스트 형태로 표시 연결 리스트를 가리키는 포인터 배열 경로에 관한 정보가 아님 .
c 를 나타내는 A[2] 에 대한 연결 리스트가 deb 라고 해서 경로가 그렇다는 것은 아님
Data Structure23 Vertext list
3. Graph Storage StructuresAdjacency List ( 인접 리스트 )
Data Structure24
3. Graph Storage StructuresAdjacency List ( 인접 리스트 )
무방향 그래프 (Undirected Graph) 인 경우 하나의 간선에 대해 두 개의 노드가 나타남 . 인접 리스트의 노드 수는 간선 수의 2 배
방향 그래프 (Directed Graph) 인 경우 하나의 간선이 정확히 한번 나타남
Data Structure25
3. Graph Storage StructuresAdjacency Matrix vs. Adjacency List
정점 i 와 정점 j 가 인접해 있는가의 판단 인접행렬 (Adjacent Matrix) 가 유리
정점 i 에 인접한 모든 노드를 찾아라에 대한 연산 인접 리스트 (Adjacent List) 가 유리
공간 면에서 인접행렬은 2V 개의 공간 , 인접 리스트는 2E 개의 공간이 필요
희소 그래프 , 조밀 그래프 간선 수가 적은 그래프를 희소 그래프 ( 稀少 , Sparse Graph) 간선 수가 많은 그래프를 조밀 그래프 ( 稠密 , Dense Graph) 희소 그래프일 수록 인접 리스트가 유리
Data Structure26
3. Graph Storage StructuresWeighted graph ( 가중치 그래프 )
Network 이라고도 함 a graph whose edges are weighted 용도 : 정점 사이를 이동하는데 필요한 비용이나 거리를 알아봄
Data Structure27
3. Graph Storage StructuresRepresentation of Weighted Graph
3. Graph Storage StructuresSpanning Tree
any tree that consists solely of edges in G that includes all the vertices in G
Spanning tree G’ is a minimal subgraph of G such that V(G’) = V(G) and G’ is connected Any connected graph with n vertices must have n-1
edges.
When a number of vertex is n, all connected graphs with n-1 edges are trees
G Spanning Trees of G
3. Graph Storage StructuresMinimum (Cost) Spanning Tree
Spanning tree of least cost (sum of weights) Every vertices are included Total edge weight is minimum possible
Minimum (Cost) Spanning Tree Algorithms Kruskal’s algorithm Prim’s algorithm Sollin’s algorithm
Study in Algorithm Class!!!!!
Data Structure31
기말고사 일시 : 6 월 19 일 오후 7 시 장소 : B 동 315 시험 범위 : 6 장 ~ 11 장