Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5...

60
IT Discipline ITD1111 Discrete Mathematics & Statistics ST DTLP Unit 5 Graphs & Trees 1 Unit 5 Discrete Mathematics and Statistics Graphs and Trees

Transcript of Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5...

Page 1: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

1

Unit 5 Discrete Mathematics and Statistics

Graphs and Trees

Page 2: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

2

Because many situations and structures give rise to graphs, graph theory has become an important mathematical tool in a wide variety of subjects, ranging from operations research, computing science and linguistics [ 語言學 ] to chemistry and genetics

[ 基因 ].

Recently, there has been considerable interest in tree structures arising in computer science and artificial intelligence. We often organize data in a computer memory store or the flow of information through a system in tree structure form. Indeed, many computer operating systems are designed to be tree structures.

Introduction

Page 3: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

3

P Q

R

ST

road map

P Q

R

ST

Diagrammatic Representation

5.1 What is a Graph

P Q

T S

R

electrical network

Page 4: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

4

An undirected graph G consists of a non-empty set of

elements, called vertices [ 頂點 ],

and a set of edges [ 邊 ], where each edge is associated with

a list of unordered pairs of either one or two vertices called

its endpoints. The correspondence from edges to end-points

is called an edge-endpoint function.

5.2 Undirected Graph

Page 5: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

5

Edge e1 e2 e3 e4

Endpoints {u, v} {u, w} {v, w} {w, z}

u

v w

z

e1e2

e3

e4

vertex-set V(G) = {u, v, w, z}

edge-set E(G) = {e1, e2, e3, e4}

edge-endpoint function

Example 5.2-1 (Undirected Graph)

Page 6: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

6

A directed graph G consists of vertices, and a

set of edges, where each edge is associated with a

list of ordered pair endpoints

5.3 Directed Graph

Page 7: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

7

Edge e1 e2 e3 e4

Endpoints (u, v) (w, u) (w, v) (z, w)

vertex-set V(G) = {u, v, w, z}

edge-set E(G) = {e1, e2, e3, e4}

edge-endpoint function

u

v w

z

e1e2

e3

e4

Example 5.3-1 (Directed Graph)

Page 8: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

8

Two or more edges joining the same pair of vertices are called multiple edges and an edge joining a vertex to itself is called a loop.

The degree of a vertex is the number of edges meeting at a given vertex.

5.4 Multiple edges , Loop and Degree

Page 9: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

9

V(G) = {u, v, w, z}

E(G) = {e1, e2, e3, e4, e5, e6, e7}

edge-endpoint function

u v

w z

Multiple edges

loop

e1

e2 e3 e4

e5e6e7

deg u = 6, deg v = 5, deg w = 2, deg z = 1

total degree = 6 + 5 + 2 + 1 = 14

Edge e1 e2 e3 e4 e5 e6 e7

Edge points {u, u} {u, w} {v, w} {v, z} {u, v} {u, v} {u, v}

Example 5.4-1 (Multiple edges , Loop and Degree)

Page 10: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

10

A graph G is connected if

there is a path in G between

any given pair of vertices, and

disconnected otherwise.

Connected Graph

Disconnected Graph

components

5.5 Connected and Disconnected Graphs

Page 11: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

11

K2K3 K4

K5

V1 V2

V1

V2

V3

V1

V2

V3

V4

V1

V2

V3

V4V5

A complete graph on n vertices , denoted Kn, is a simple graph with n vertices v1, v2, ……vn whose set of edges contains exactly one edge for each pair of distinct vertices.

5.6 Complete graph

Page 12: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

12

In any graph, the sum of all the vertex-degrees is equal to twice the number of edges.(see

e.g.3)

No. of edges =7

total degree = 6 + 5 + 2 + 1 = 14

As the consequences of the Handshaking Lemma, the

sum of all the vertex-degrees is an even number and the

number of vertices of odd degree is even.(e.g. 3 odd deg

vertices are:v and z)

5.7 Handshaking Lemma [輔助定理 ]

Page 13: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

13

0122

1010

2101

2010v 1

v 2

v 3

v 4

v 1 v2 v3 v4

A(G) =

v1v2

v3v4

Adjacency [ 毗鄰 ] Matrix A(G)

5.8 Matrix Representations of Undirected Graph

Page 14: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

14

Incidence [ 關聯 ] Matrix I(G)

v1v2

v3v4

e1

e2

e3

e4 e5

e6

e7

1111100

0000110

1100011

0011001e1 e2 e3 e4 e5 e6 e7

v 1

v 2

v 3

v 4

I(G) =

Page 15: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

15

Adjacency Matrix A(G)

v1

V2

V3

e1e2 e3

e4

e5

100

201

010v 1

v 2

v 3

v 1 v2 v3

A(G) =

5.9 Matrix Representations of Directed Graph

Page 16: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

16

Incidence Matrix I(G)

v1

V2

V3

e1e2 e3

e4

e5

v 1

v 2

v 3

e1 e2 e3 e4 e5

I(G) =

21100

01111

00011

Page 17: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

17

A walk of length k between v1 and v8 in a graph G is a succession of k edges of G of the form v1e1v2, v2e2v3, v3e3v4, … ,v7e7v8.

We denote this walk by v1e1v2e2v3e3v4e4v5e5v6e6v7e7v8.

v1v2

v3

v4

v5

v6

v7e1

e2 e3

e4

e5

e6e7

v8

5.10 Walk

Page 18: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

18

If all the edges (but not necessarily all the vertices) of a walk are different, then the walk is called a path.

If , in addition, all the vertices are different, then the trail is called simple path.

A closed path is called a circuit.

A simple circuit is a circuit that does not have any other repeated vertex except the first and last.

5.11 Paths and circuits

Page 19: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

19

v1 v3

v5

v4v2

path

v1 v3

v5

v4v2simple path

v1 v2 v4 v1 v3 v5 is a path v1 v2 v4 v3 v5 is a simple path

Example 5.11-1 (Paths)

Page 20: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

20

v1 v3

v5

v4v2

circuit

v1 v3

v5

v4v2

simple circuit

v1 v2 v4 v3 v5 v4 v1 is a circuit v1 v2 v4 v5 v3 v1 is a simple circuit

Example 5.11-2 (Circuits)

Page 21: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

21

Repeated Edge Repeated Vertex

Starts and Ends at Same Point

WalkPathSimple pathClosed walkCircuitSimple circuit

AllowedNoNo

AllowedNoNo

AllowedAllowed

NoAllowedAllowed

First and last only

AllowedAllowed

NoYesYesYes

Summarized Table

Page 22: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

22

If G is a graph with vertices v1, v2, …… vm and A(G) is the adjacency matrix of G, then for each positive integer n,

the ijth entry of An = the number of walks of length n from vi to vj.

5.12 Counting Walks of Length N

Page 23: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

23

020

211

010

Av1

v2

v3

e1

e2

e3 e4

Adjacency matrix A(G)

Example 5.12-1 (Counting Walks)

Page 24: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

24

422

261

211

A2

one walk of length 2 connecting v1 to v1

(v1e1v2e1v1)

two walks of length 2 connecting v1 to v3

(v1e1v2e3v3, v1e1v2e4v3)

Example 5.12-1 (cont.)

Page 25: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

25

The objective of this algorithm is to find the shortest

path from vertex S to vertex T in a given network.

We demonstrate the steps of the algorithm by

finding the shortest distance from S to T in the

following network:

5.13 The Shortest Path Algorithm

Page 26: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

26

7

4

9

7

1

3

1

6

3

4

S

A

TB

C

D

Example 5.13-1 (Shortest Path Alg.)

Page 27: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

27

7

4

9

7

1

3

1

6

3

4

S

A

TB

C

D

0

7

4

9

7

Example 5.13-1(Cont.)

Page 28: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

28

7

4

9

7

1

3

1

6

3

4

S

A

TB

C

D

0

5

4

7

7

Example 5.13-1(Cont.)

Page 29: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

29

7

4

9

7

1

3

1

6

3

4

S

A

TB

C

D

0

5

4

7

7

11

Example 5.13-1(Cont.)

Page 30: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

30

7

4

9

7

1

3

1

6

3

4

S

A

TB

C

D

0

5

4

7

7

10

Example 5.13-1(Cont.)

Page 31: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

31

7

4

9

7

1

3

1

6

3

4

S

A

TB

C

D

0

5

4

7

7

10

Therefore, the shortest path from S to T is SBCT with path length 10

Example 5.13-1(Cont.)

Page 32: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

32

Initialization

Assign to vertex S potential 0.

Label each vertex V reached directly from S with distance from S to V.

Choose the smallest of these labels, and make it the potential of the corresponding vertex or vertices.

5.13 The Shortest Path Algorithm Extra Notes

Page 33: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

33

Step Visited A B C D T

Init B 7S 4S 9S 7S X

Page 34: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

34

Step Visited A B C D T

Init B 7S 4S 9S 7S X

1 A 5SB 4S 7SB 7S X

Page 35: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

35

Step Visited A B C D T

Init B 7S 4S 9S 7S X

1 A 5SB 4S 7SB 7S X

2 D 5SB 4S 7SB 7S 11SBA

Page 36: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

36

Step Visited A B C D T

Init B 7S 4S 9S 7S X

1 A 5SB 4S 7SB 7S X

2 D 5SB 4S 7SB 7S 11SBA

3 C 5SB 4S 7SB 7S 11SBA

Page 37: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

37

Step Visited A B C D T

Init B 7S 4S 9S 7S X

1 A 5SB 4S 7SB 7S X

2 D 5SB 4S 7SB 7S 11SBA

3 C 5SB 4S 7SB 7S 11SBA

4 T 5SB 4S 7SB 7S 10SBC

Page 38: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

38

A connected graph G is Eulerian if there is a closed path which includes every edge of G; such a path is called an Eulerian path, and if the path which starts and ends on the same vertex, then it is called Eulerian circuit.

1

2

3

4

56

7

8

p q

r

st

5.14 Eulerian Graphs

Page 39: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

39

Theorem (Eulerian Graph)

Let G be a connected graph. Then G has an Eulerian circuit if and only if every vertex of G has even degree,and has an Eulerian path if no more than two vertices have an odd degree.

Which of the following graph(s) is/are Eulerian?

(a) (b) (c) (d)

Page 40: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

40

The four places (A, B, C and D) in the city of Königsberg were interconnected by seven bridges (p, q, r, s, t, u and v) as shown in the following diagram. Is it possible to find a route crossing each bridge exactly once ?

Königsberg

A

B

C

D

p q

rs

t

u

v

5.15 Königsberg bridges problem

Page 41: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

41

By the theorem, it is not a Eulerian graph. It follows that there is no route of the desired kind crossing the seven bridges of Königsberg.

We can express the Königsberg bridges problem in terms of a graph by taking the four land areas as vertices and the seven bridges as edges joining the corresponding pairs of vertices.

C

A

B

D

p

r s

q

t

u

v

Answer (Königsberg bridges problem)

Page 42: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

42

STEP 1 Choose a starting vertex u with a vertex of odd degree.

STEP 2 At each stage, traverse [橫越 ] any available edge, choosing a bridge only if there is no alternative.

STEP 3 After traversing each edge, erase [擦掉 ] it (erasing any

vertices of degree 0 which result), and then choose

another available edge.

STEP 4 STOP when there are no more edges.

5.16 Fleury’s Algorithm

Page 43: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

43

Find the Eulerian path of the following graph.

b f

ac

d

e

u

Example 5.16-1 (Fleury’s Algorithm)Constructing Eulerian paths and circuits

Page 44: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

44

Starting at u, we may choose the edge ua, followed by ab. Erasing these edges and the vertex a give us graph (b)

b f

ac

d

e

u

(a)

Example 5.16-1 (Cont.)

Page 45: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

45

We cannot use the edge bu since it is a bridge, so we choose the edge bc, followed by cd and db. Erasing these edges and the vertices c and d give us graph (c)b f

c

d

e

u

(b)

Example 5.16-1 (Cont.)

Page 46: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

46

We have to traverse the bridge bu. Traversing the cycle uefu completes the Eulerian path. The path is therefore uabcdbuefu.

b f

e

u(c)

Example 5.16-1 (Cont.)

Page 47: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

47

A connected graph G is Hamiltonian if there is a cycle which includes every vertex of G ; such a cycle is called a Hamiltonian cycle.

p q

rs

t

p q

Hamiltonian Graphrs

t

Hamiltonian Cycle

5.17 Hamiltonian Graphs

Page 48: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

48

Let G be a simple graph with n vertices, where n 3. If deg v n/2 for each vertex v, then G is Hamiltonian.

For the above graph, n = 6 and deg v = 3 for each vertex v, so this graph is Hamitonian by Dirac’s theorem.

5.18 DIRAC’S THEOREM

Page 49: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

49

Let G be a simple graph with n vertices, where n 3.

If deg v + deg w n,

for each pair of non-adjacent vertices v and w, then G is Hamiltonian.

5.19 ORE’S THEOREM

Page 50: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

50

n = 5 but deg u = 2, so Dirac’s theorem does not apply.

However, deg v + deg w 5 for all pairs of non-adjacent vertices v and w, so this graph is Hamiltonian by Ore’s theorem.

u

Example 5.19-1 (Ore’s Thm)

Page 51: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

51

A tree is a connected graph which contains no cycles.

Properties of Tree• Every tree with n vertices has exactly n 1 edges.

• Any two vertices in a tree are connected by exactly one path.

• Each edge of a tree is a bridge.

5.20 Trees

Page 52: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

52

• T is connected and has n 1 edges.• T has n 1 edges and contains no cycles.• T is connected and each edge is a bridge.• Any two vertices of T are connected by exactly one path.

5.21 Alternative definitions of the tree

Page 53: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

53

Let G be a connected graph. A spanning tree in G is a subgraph of G that includes all the vertices of G and is also a tree. The edges of the tree are called branches.

5.22 Spanning [ 包括 , 延伸 ] Trees

Page 54: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

54

v w

x

yz

v w

x

yz

v w

x

yz

v w

x

yz

A graph G

Spanning Trees

Example 5.22-1 (Spanning Trees)

Page 55: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

55

Let T be a spanning tree of minimum total weight in a connected weighted graph G. Then T is a minimum spanning tree of G.

5.23 Minimum Spanning Tree

Page 56: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

56

Illustrated Example

A

C B

D

E

2 6

7 5

9

64

85

8

5.24 Greedy Algorithm

Page 57: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

57

Iteration 1 (Choose an edge of minimum weight)

A

C B

D

E

2 6

7 5

9

64

85

8

5.24 Greedy Algorithm (cont.)

Page 58: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

58

Iteration 2 (Select the vertex from unconnected set {A,B,C} that is closest to connected set {D,E})

A

C B

D

E

2 6

7 5

9

64

85

8

5.24 Greedy Algorithm (cont.)

Page 59: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

59

Iteration 3 (Select the vertex from unconnected set {A,C} that is closest to connected set {B,D,E,})

A

C B

D

E

2 6

7 5

9

64

8

8

5.24 Greedy Algorithm (cont.)

Page 60: Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP

Unit 5 Graphs & Trees

60

Iteration 4 (Select the vertex from unconnected set {C} that is closest to connected set {A,B,D,E})

A

C B

D

E

2

7 5

9

4

8

8

5.24 Greedy Algorithm (cont.)