• 沒有找到結果。

§8.1 Introduction to Graphs

N/A
N/A
Protected

Academic year: 2022

Share "§8.1 Introduction to Graphs"

Copied!
65
0
0

加載中.... (立即查看全文)

全文

(1)

Discrete

Mathematics

Chapter-8

Graphs

(2)

§8.1 Introduction to Graphs

„ Def 1. A (simple) graph G=(V,E) consists of a nonempty set V of vertices, and E, a set of unordered pairs of distinct elements of V called edges.

„ eg.

V1

V2

V3 V4

V7

V6

G=(V,E), where V={ v1,v2,…,v7 }

E={ {v1,v2}, {v1,v3}, {v2,v3} {v3,v4}, {v4,v5}, {v4,v6} {v4,v7}, {v5,v6}, {v6,v7} }

V5

(3)

„ Def 2. Multigraph

simple graph + “兩點間允許多條邊”

multiedge

eg.

V1

V2

V3 V4

V5

V7

V6

(4)

„ Def 3. pseudo graph :

simple graph + multiedge + loop

( loop即 )

eg.

(5)

„ Table 1. Graph Terminology

Type Edges Multiple

Edges

Loops (simple) graph

Multigraph

Pseudo graph Directed graph

Directed multigraph

Directed

表示成 (u,v) Undirected 表示成 {u,v}

(6)

„ Note: directed multigraph 中

U V

是 multiedge 邊為(u,v),(u,v)

U V

不是 multiedge 邊為(u,v),(v,u)

Exercise : 3,5,6,7,9

(7)

§8.2 Graph Terminology

„ Def 1. Two vertices u and v in a graph

G are called adjacent in G if {u,v} is an edge of G.

„ Def 2. The degree of a vertex v, denoted

by deg(v), in an (undirected) graph is the number of edges incident with it.

(undirected)

(Note : 點跟點相連 : adjacent 點跟邊相連 : incident )

(Note : loop要算2次)

(8)

„ Example 1. What are the degree of the vertices in the graph H ?

„ Sol :

a b

c

e d f

H

deg(a)=4 deg(b)=6 deg(c)=1 deg(d)=5 deg(e)=6 deg(f)=0

(9)

„ Def. A vertex of degree 0 is called isolated.

eg. “ f ” in Example 1.

Thm 1. (The Handshaking Theorem)

Let G=(V,E) be an undirected graph with n edges (i.e., |E|=n).

Then

=

V v

n v ) 2 deg(

Pf : 每條edge {u,v}會貢獻一個degree給u跟v

(10)

„ eg. Example 1. there are 11 edges, and

=

V v

v ) 22 deg(

Example 2. How many edges are there in a graph with 10 vertices each of degree 6 ?

Sol :

10 ⋅ 6 = 2n => n=30

(11)

„ Thm 2. An undirected graph has an even number of vertices of odd degree.

„ Def 3. G: directed graph , G=(V,E) (u,v)∈E : u is adjacent to v

v is adjacent from u

u : initial vertex , v : terminal vertex

u v

(12)

„ Def 4.

G=(V,E) : directed graph, v∈V

deg-(v) : # of edges with v as a terminal.

(in-degree)

deg+(v) : # of edges with v as a initial vertex (out-degree)

(13)

„ Example 3.

a b

c

e d

f

a is adjacent to b , b is adjacent from a a : initial vertex of (a,b)

b : terminal vertex of (a,b)

deg-(a)=2, deg+(a)=4 deg-(b)=2, deg+(b)=1

: :

deg-(f)=0, deg+(f)=0

(14)

„ Thm 3. Let G=(V,E) be a digraph. Then

pf :

每個 edge貢獻一個 out–degree 給 a

一個 in–degree 給 b

a b

∑ ∑

+

= =

V

v v V

E v

v ) deg ( ) (

deg

(15)

Def : The complete graph on n vertices, denoted by Kn, is the simple graph that contains

exactly one edge between each pair of distinct vertices.

Example 4.

K1 K2 K3 K4

Note : | E | =

n 2

(16)

„ Example 5. The cycle Cn, n≧3, consists of n vertices v1,v2,…,vn and edges

{v1,v2}, {v2,v3},…,{vn-1,vn},{vn,v1}.

C5 C6

| E | = n

(17)

„ Example 6. Wn : (wheel), Cn中加一點連至 其餘n點(n≧3)

W5 W6

| V | = n + 1

| E | = 2n

(18)

„ Def 5. A simple graph G=(V,E) is called

bipartite if V can be partitioned into V1 and V2, V1∩V2=∅, such that every edge in the graph connect a vertex in V1 and a vertex in V2.

Example 8.

v1 v3

v5

v2 v4 v6

∴ C6 is bipartite.

(19)

Example 10. Is the graph G bipartite ?

a b

g

f

e

d c

a

b

g f e

d

c

Yes !

(20)

„ Example 11. Complete Bipartite graphs (km,n) ???

K2,3 K3,3

Note. | E | = mn

(21)

„ Example 14. A subgraph of K5

Def 6. A subgraph of a graph G=(V,E) is a

graph H=(W,F) where W ⊆ V and F ⊆ E.

(注意 F 要連接 W 裡的點)

a

b

d c e

a

e b

c

subgraph of K5 K5

(22)

„ Def 7. The union of two simple graph G1=(V1,E1) and G2=(V2,E2) is the

simple graph G1∪G2=(V1∪V2,E1∪E2)

„ Example 15.

a b c

d f

a b c

d e

a b c

d e f

G1 G2

G1∪G2

(23)

ex35上面 A simple graph G=(V,E) is called regular if every vertex of this graph has the same degree. A regular graph is called

n-regular if deg(v)=n , ∀v∈V.

eg.

K4 : is 3-regular.

Exercise : 5,7,21,23,25,35,37

(24)

§8.3 Representing Graphs and Graph Isomorphism

※Adjacency list

Example 1. Use adjacency list to describe the simple graph given below.

b a

e d

c

Vertex Adjacent vertices

a b,c,e

b a

c a,d,e

d c,e

e a,c,d

Sol :

(25)

„ Example 2. (digraph)

a

b

e

c

d

Initial vertex Terminal vertices

a b,c,d,e

b b,d

c a,c,e

d

e b,c,d

(26)

※Adjacency Matrices

Def. G=(V,E) : simple graph,

V={v1,v2,…,vn}. (順序沒關系)

A matrix A is called the adjacency matrix of G if A=[aij]nxn , where

=

0 0

1 1

0 0

1 1

1 1

0 1

1 1

1 0

A1

Example 3.

a

c

b

d

undirected graph 的連 通矩陣必

“對稱”

=

0 1

1 1

1 0

0 1

1 0

0 1

1 1

1 0

2 A

a b c d

a b c d b d c a

b d c a

(27)

Example 5. (Pseudograph) (矩陣未必是0,1矩陣.)

Def. If A=[aij] is the adjacency matrix for the directed graph, then

=

0 2 1 2

2 1 1 0

1 1 0 3

2 0 3 0 A

a b c d

a b c d

a

ij

=

1 , if

0 , otherwise

故矩陣 未必對稱

a b

c d

vi vj

(28)

„ Def 1.

The simple graphs G1=(V1,E1) and G2=(V2,E2) are isomorphic if there is an one-to-one and onto function f from V1 to V2 with the property that a~b in G1 iff f(a)~f(b) in G2, ∀a,b∈V1

f is called an isomorphism.

※Isomorphism of Graphs

u1

u3

u2

u4

G

v1

v3

v2

v4

H

G is isomorphic to H

(29)

„ Example 8.

u1

u3

u2

u4

G

v1

v3

v2

v4

H

f(u1) = v1 f(u3) = v3 f(u2) = v4 f(u4) = v2

※Isomorphism Graphs 必有 : (1) 相同的點數。

(2) 相同的邊數。

(3) 相同的degree分佈。

(30)

※給定二圖,判斷它們是否isomorphic的問題一般來說不 易解,而且答案常是否定的。

Example 9.

Show that G and H are not isomorphic.

a

e

b

c

d

b

a

e d

c

Sol :

∵ H 有 degree = 1 的點,G 沒有

∴ G ≈ H

G H

(31)

Example 10.

Determine whether G and H are isomorphic.

G H

a b

d c

e

h

f g

s

v

t

u

w x

z y

Sol :

∵ G 中 degree 為 3 的點有d, h, f, b 它們不能接成 4-cycle

但 H 中 degree 為3的點有s, w, z, v 它們可接成 4-cycle

∴ 不是 isomorphic.

另法 : G 中 degree 為 3 的點,旁邊都只連了另一個 deg = 3 的點 但 H 中 deg = 3 的點旁邊都連了 2 個 deg = 3 的點。

(32)

Example 11. Show that G H

G H

u1 u2

u4 u3

u5

u6

v1

v2

v3

v4

v5 v6

Exercise : 3,7,14,17,19,23,37,39

(1) 相同的點數。

(2) 相同的邊數。

(3) 相同的degree分佈

(33)

§8.4: Connectivity

Def. 1,2 :

„ In an undirected graph, a path of length n from u to v is a sequence of adjacent vertices going from vertex u to vertex v. (e.g., P: u=x0, x1,

x2, …, xn=v)

„ Note. A path of length n has n+1 verticesn edges

„ A path is a circuit if u=v.

„ A path traverses the vertices along it.

„ A path or circuit is simple if it contains no vertex more than once. (simple circuit通常稱為cycle)

(34)

Paths in Directed Graphs

„ Same as in undirected graphs, but the

path must go in the direction of the arrows.

Figure 5.

u v

(35)

Connectedness

Def. 3:

An undirected graph is connected (連通) iff there is a path between every pair of distinct vertices in the graph.

Def:

Connected component: maximal

connected subgraph. (一個不連通的圖 會有好幾個component)

Example 6

(36)

Connectedness

Def:

A cut vertex separates one connected component into several components if it is removed.

Def:

A cut edge separates one connected component into two components if it is removed.

Example 8.

(37)

Connectedness in Digraphs

Def. 4:

A directed graph is strongly connected iff there is a directed path from a to b for any two

vertices a and b.

Def. 5:

It is weakly connected iff the underlying

undirected graph (i.e., with edge directions removed) is connected .

„ Note strongly implies weakly but not vice-versa.

(38)

Connectedness in Digraphs

Example 9.

„ G is strongly/weakly connected

„ H is only weakly connected

(39)

Paths & Isomorphism

„ Note that connectedness, and the existence of a circuit or simple circuit of length k are graph

invariants with respect to isomorphism.

„ Example 12: Determine whether the graphs G and H shown in Figure 6 are isomorphic

(40)

Example 12

„ Sol: Both G and H have six vertices and eight edges. Each has four vertices of degree three, and two vertices of degree two.

„ However, H has a simple circuit of length three, namely, v1, v2, v6, v1, whereas G has no simple circuit of length three, as can be determined by inspection (all simple circuits in G gave length at least four). Because the existence of simple

circuit of length three is an isomorphic invariant, G and H are not isomorphic.

(41)

Paths & Isomorphism

„ Example 13: Determine whether the graphs G and H shown in Figure 7 are isomorphic

(42)

Example 13

„ Both G and H have five vertices and six edges. Each has two vertices of degree three, and three vertices of degree two, and both have a simple circuit of length

three, a simple circuit of length four, and a simple circuit of length five.

„ G and H are isomorphic.

(43)

Counting Paths between Vertices

Let A be the adjacency matrix of graph G.

Theorem 2:

The number of paths of length r from vi to vj is equal to (Ar)i,j. (The notation (M)i,j denotes mi,j where [mi,j] = M.)

Example 14.

Exercise: 15, 23, 25, 26

(44)

Example 14.

„ How many paths of length four are there from a to d in the simple graph G in Figure 8?

„ Sol: a,b,a,b,d; a,b,a,c,d; a,b,d,b,d;

a,b,d,c,d; a,c,a,b,d; a,c,a,c,d; a,c,d,b,d;

a,c,d,c,d.

=

0 1

1 0

1 0

0 1

1 0

0 1

0 1

1 0

A

=

8 0

0 8

0 8

8 0

0 8

8 0

8 0

0 8

A4

(45)

§8.5: Euler & Hamilton Paths

Def. 1:

„ An Euler circuit in a graph G is a simple circuit containing every edge of G.

„ An Euler path in G is a simple path containing every edge of G.

Example 1.

(46)

Example 1

(47)

Example 2

„ Which of the directed graphs in Figure 4 have an Euler circuit? Of those that do not, which have Euler path?

(48)

Example

„ Sol: The graph H2 has Euler circuit, for example, a,g,c,b,g,e,d,f,a.

„ Neither H1 nor H3 has Euler circuit. H3

has an Euler path, namely, c,a,b,c,d,b, but H1 does not.

(49)

Useful Theorems

Thm. 1:

A connected multigraph has an Euler circuit iff each vertex has even degree.

Thm. 2:

A connected multigraph has an Euler path (but not an Euler circuit) iff it has exactly 2 vertices of odd degree.

(50)

Example 4

„ Which graphs shown in Figure 7 have an Euler path?

(51)

Example 4

„ Sol: G1 contains exactly two vertices of odd

degree, namely, b and d. Hence, it has an Euler path that must have b and d as its endpoints.

One such Euler path is d,a,b,c,d,b.

„ Similarly, G2 has exactly two vertices of odd

degree, namely, b and d. So it has an Euler path that must have b and d as endpoints. One such Euler path is b,a,g,f,e,d,c,g,b,c,f,d.

„ G3 has no Euler path because is has six vertices of odd degree.

(52)

Hamilton Paths

Def. 2:

„ A Hamilton circuit is a circuit that

traverses each vertex in G exactly once.

„ A Hamilton path is a path that traverses each vertex in G exactly once.

(53)

Example 5

„ Which of the simple graphs in Figure 10 have a Hamilton circuit or, if not, a Hamilton Paths?

(54)

Example 5

„ Sol: G1 has a Hamilton circuit: a,b,c,d,e,a.

„ There is no Hamilton circuit in G2 (this can be seen by nothing that any circuit containing every vertex must contain the edge {a,b} twice), but G2 does have a Hamilton path, namely, a,b,c,d.

„ G3 has neither a Hamilton circuit nor a Hamilton path, because any path containing all vertices

must contain one of the edges {a,b},{e,f}, and {c,d} more than once.

(55)

Useful Theorems

Thm. 3 (Dirac’s Thm.):

If (but not only if) G is connected, simple, has n≥3 vertices, and deg(v)≥n/2 ∀v, then G has a Hamilton circuit.

Exercise: 3, 5, 7, 21, 26, 28, 42, 43.

(56)

§8.6: Shortest Path Problems

Def:

Graphs that have a number assigned to each edge are called weighted graphs.

Shortest path Problem:

Determining the path of least sum of the weights between two vertices in a

weighted graph.

(57)

Dijkstra’s Algorithm

Figure 4.

Exercise: 3

(58)
(59)

§8.7: Planar Graphs

Def. 1:

A graph is called planar if it can be drawn in the plane without any edge crossing.

Exercise: 2,3,4

(60)

Example 1

„ K4 is planar.

(61)

Example 3

„ K3,3 is nonplanar.

(62)

§8.8: Graph Coloring

Def. 1:

A coloring of a simple graph is the

assignment of a color to each vertex of the graph so that no two adjacent

vertices are assigned the same color.

Def. 2:

The chromatic number of a graph is the least number of colors needed for a

coloring of this graph. (denoted by χ(G))

(63)

§8.8: Graph Coloring

Example 2~4: χ(Kn)=n, χ(Km,n)=2, χ(Cn)=2,3.

Example 3’: If G is a bipartite graph, χ(G)=2.

Theorem 1. (The Four Color Theorem)

The chromatic number of a planar graph is no greater than four.

Exercise: 6, 7

(64)

Example 1

„ What are the chromatic number of graphs G and H show in Figure 3?

(65)

Example 2

„ What is the chromatic number of Kn ?

„ Sol: Here, the chromatic number of Kn = n.That is, χ(Kn)=n. (Recall that Kn is not planar when n >=5, so this does not contradict the four color Theorem.) A coloring of K5 using five colors is shown in Figure 5.

參考文獻

相關文件

vertices’ edges, in this shortest path, the left edge must be relaxed before the right edge.  One phase of improvement

• If a graph contains a triangle, any independent set can contain at most one node of the triangle.. • We consider graphs whose nodes can be partitioned into m

In this project, we discovered a way to make a triangle similar to a target triangle that can be inscribed in any given triangle. Then we found that every triangle we’ve made in a

The design of a sequential circuit with flip-flops other than the D type flip-flop is complicated by the fact that the input equations for the circuit must be derived indirectly

Show that the requirement in the definition of uniform continuity can be rephrased as follows, in terms of diameters of sets: To every  > 0 there exists a δ > 0 such that

Graph Algorithms Euler Circuit Hamilton Circuit.. for Sprout 2014 by Chin

Graph Algorithms Euler Circuit Hamilton Circuit.. for Sprout 2014 by Chin

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005..