chapter 10 graph theory. 10.2 eulerian cycle and the property of graph theory 10.3 the important...

Post on 14-Jan-2016

238 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Chapter 10

Graph Theory

10.2 Eulerian Cycle and the property of graph theory10.3 The important property of graph theory and its representation10.4 Shortest path

10.2 Eulerian Cycle and the property of graph theory

Example 1 What is Königsberg Bridge problem?

Ans.Two islands A and B are reduced to nodes.

On the side of the river C and D are also reduced to nodes, it can be modeled as a graph and it is shown in Fig. 10.2.1.

G=(V,E), V denotes Node Set, and E denotes Edge Set. V={A,B,C,D} and E={(A,C),(A,C),(A,D),(A,D),(A,B),(B,C),(B,D)}.

Fig.10.2.1 Königsberg Bridge

Fig.10.2.2 The model of Fig. 10.2.1

Edge(A,C) appears two times, it is called Multiple Edges.The degree of node B is 3, it can be denoted by d(B)=3 which

means that there are 3 edges incident to the node B.

Example 2 From Fig. 10.2.2, Can we find an Eulerian cycle from node A?Ans.

Node C will consume two adjacency edges when we cross. Since d(C) is odd, there will remain at last an adjacency edge. The discussion on node C is also suitable for node A, since d(A) is also odd. We are unable to find an Eulerian cycle in Fig.10.2.2.

Example 2.1 Let G=(V,E) be a loop-free connected undirected graph, and let (a, b) be an edge of G. Prove that (a, b) is a part of a cycle if and only if remove the vertices a and b does not disconnect G.Ans. () If (a, b) is a part of a cycle and let a-b-v1-v2-…vi-a be a cycle. Suppose remove edge (a, b) from G. The path b-v1-v2-…-vi-a connects (a, b), thus G still connect. ()It is still a connected image when removing the edge (a,b) from G, thus there exists a path a-v1-v2-…-vi-b. If we replace edge (a, b), we can obtain image G with a cycle a-v1-v2-…-vi-b-a, thus (a, b) is a part of a cycle.

Example 3 Let G=(V,E) be a connected graph. Prove that G has an Eulerian cycle if and only if all degree of nodes in G are even?Ans. () If G has an Eulerian cycle, it means that for all nodes in the cycle, the number of in-edges are equal to out-edges. Thus, for all nodes in G, the degree of them are all even. () Assume that we select two different node x, yV from G, and it forms a longest Eulerian Chain C1 from x to y. At this moment, we must select an edge (y, z) not be a part of C1 from G. Then, add an edge (y, z) to C1, we have a longer Eulerian chain . In fact, node z is node x . Assume that C1 has included all the edges in G, we get the proof.

If there are still edges in G which extend from node uC1 but are not a part of C1, let G’ be discarded the edge set of C1 in G. Since G is a connected graph and every degree of node is even, the degree of nodes in G’ are still even. Assume we can find a cycle in G’, we merge this cycle into C1, we have Eulerian cycle larger than C1, this is a contradiction.

Discard multiple edges (A,D) and (A,C) in figure 10.2.2, we can also

find an Eulerian chain.

Example3.1 Given G=(V,E), are the number of odd degree nodes even?

Ans. Two nodes A and B(as shown in fig. 10.2.3)

.

.

.

.A B

. .

Fig. 10.2.3 The case of shared edge

We consider once edge (A,B) when computing d(A). When computing d(B), we consider edge(A,B) once more. From above, we can guess that

oddisVd evenisVd

ji

V

ii

i j

VdVdEVd 1

2

oddisVdi

i

kVd

12 (10.2.1)

Thus, the number of odd degree nodes are even.

Example3.2 How many edges does a graph have if it has vertices of degree 5, 2, 2, 2, 2, 1? Draw the graph. Ans. According to the discussion of Q4, let the graph G = (V, E) has vertices of degree 5, 2, 2, 2, 2, 1, since

2| |= deg( )v V

E v 5 2 2 2 2 1 =14

Thus, | E | = 7. The corresponding figure is as follow:

Example3.3 Suppose a connected planar graph G has five vertices with degree 2, two vertices with degree 3, and three vertices with degree 4. Find the number of region G has. Ans.

Let G = (V, E), we have:

2| |= deg( )v V

E v

Thus, we have

2 |E| = 2 5 + 3 2 + 4 3 = 28.

Therefore, | E | = 14. From Euler formula we know that | V | | E | + | F | = 2, for |V | is the number of nodes, |E| is the number of edges, |F| is the number of region. We have

| F | = | E | |V| + 2 = 14 (5 + 2 + 3) + 2 = 6

對某一個選區的候選人而言,他/她有興趣的是在選前將區內的所有椿腳

全部拜訪完,但同一點不可拜訪二次。

Example4 Can the preceding statement about the visiting movement of candidates be modeled as graph theory problems?

Ans. Model as Hamiltonian cycle problem. As shown in fig. 10.2.4

A

B

C

DE

F

Fig. 10.2.4 An example for Hamiltonian cycle

We visit all the nodes along the

path AFEDCBA ,except the starting node A, there are no nodes visited twice. The path is called “Hamiltonian Cycle”. The path A B C D E F is called “Hamiltonian Chain”.

有環邊(Loop Edge)

簡單圖(Simple Graph)

Example 4.1 Let EVG , be a simple connected graph and 3nV . In V , for any two unadjacent nodes x and y , assume

nydxd is true. Prove that G has Hamiltonian cycle if and only if EVG ,' has Hamiltonian cycle, where yxEE ,' .

Ans. '' If G has Hamiltonian cycle, 'G must has Hamiltonian cycle, since we are used Hamiltonian cycle of G .

'' ,By contradiction. Assume 'G has Hamiltonian cycle and G doesn’t

have Hamiltonian cycle. Since G doesn’t have Hamiltonian cycle, the Hamiltonian cycle of 'G must include edge yx, . It means there exits a

Hamiltonian chain nvvvv 321 in G , where 1vx and

nvy . Let EvvvN ii 111 , and nii vvvN ,2 . Since G doesn’t

include edge nvv ,1 , 1N and 2N are also not including nv , that is

21 NNvn , thus we obtain nNN || 21 . Next, we check whether

21 NN is zero or not. Assume 021 NN , let ivNN 21 , fig.

10.2.5 can help us to understand the proof.

. . .

. . .

1Vx

2V

3V

iV

1iV

2iV

1nV

yVn

Fig. 10.2.5 a counterexample

Thus, we find a Hamiltonian

cycle ni vvvvv 321 11 nv 11 vvi , it is in conflict with the assumption in the beginning:G doesn’t have Hamiltonian cycle. Thus 021 NN . From ydxd 21 NN 21 NN 21 NN nNN 21 ,

we know that this is in conflict with the given conditions nydxd .

Since '' pq is equal to '~' pq , if we prove by contradiction, it is similar to prove that pq is contradiction.

Example 5 What is Euler Formula?

Ans. 2 FEV

F denotes the number of regions.

1V

2V

3V

4V

3F

1F

2F

Fig. 10.2.6 An example for Euler formula.

2 FEV is absolutely true. As shown in fig. 4.2.6, we have

2354 。

Example 5.1 How to prove Euler formula?

Ans. If 1F , EVG , is a tree, 1VE . It is easy to check that

2 FEV is true.

Assume that KF , Euler formula is true.

We add a triangle region in G , that is to add a node and two edges. We obtain a new image ''' ,EVG and it satisfies 1|| VV ,

2' EE , and 1' FF . Therefore, 2|'||'||'| FEV is

true.

Example 6 What is chinese postman problem?

Ans. Since the degree of A and B are all odd, we can not find Eulerian cycle in the figure. Assume there is a postman who must walk through all the nodes once, what route does the postman go will be most effort-saving. This problem is called Chinese postman problem.

B

A

CD

F

G

E

Fig. 10.2.7 An un-single-stroke drawing example.

Example 6.1 How to solve Chinese postman problem?

Ans. Add a new edge between A and B , the degree of each node in figure 10.2.8 are all even. The path is

DCBACGBADFGED .

We use minimum cost to add extra edges so that we can solve Chinese postman problem is worth to research.

B

E

A

CD

F

G

Fig. 10.2.8 Add an edge ),( BA in fig. 10.2.7

From fig. 10.2.9, )()( DdAd 3)()( GdBd .

Fig. 10.2.9 A more complicated case

Example 6.2 How to solve Chinese postman problem which is similar to fig. 10.2.9?

Ans.

Select four nodes A , B , D , and G whose degree are odd, a set includes two nodes and there are three pairs

)],(),,[( GDBA )],(),,[( GBDA )],(),,[( DBGA

First, pair )],(),,[( GDBA , we add some edges in fig. 10.2.9 and we

obtain fig. 10.2.10.

A

CD

GE

B

Fig. 10.2.10 the condition of adding edges in the first pair

After adding new edges, we have the extra three ( = 1+2) units cost.

For the second pair )],(),,[( GBDA after adding edges, we obtain

fig. 10.2.11. It is easy to check that we need extra three units cost. Since the third pair )],(),,[( DBGA need extra four units cost,

any of the first two pairs can be used to solve Chinese postman problem and cost least.

A

CD

GE

B

Fig. 10.2.11 The condition of adding edges in the second pair.

Example 6.3 Solve weighted Chinese postman problem. Ans. Assume the first pair is

)],(),...,,(),,(),,[( 332211 kk vuvuvuvu

where 2/|| 0Vk . Considering ki 1 , assume all the shortest pathes from ui

to vi, ki 1 are found, then there are k shortest pathes will be found, let the cost of k shortest pathes are denoted by C(P1), C(P2), C(P3), ..., and C(Pk). If we use the first pair to solve chinese postman problem, we will spend additional cost

)(1

1

k

iiPCC

We compute the extra cost of each pair, assume there are t pairs, it will be the perfect pair if it satisfies the following j:

j={i |Ci is minimum,1≤i≤t}

10.3 The important property of graph theory and its representation

Fig. 10.3.1 3,3K is not a simple planar graph

Example 1 Given a simple planar graph , are there

upper bounds to limit the degree of nodes ? Ans. A face at least includes three edges. Let represents the

number of faces that are formed by i edges, then the total number of faces F in G will satisfy

Consider an edge shared by two faces, we obtain

We have

(10.3.1)

We prove it by contradiction : there is a degree of node less than 6. Assume every node in V satisfy 6, we obtain

(10.3.2)

||33||233

FFiFEm

i

im

i

i

m

i

im FFFFF3

43 ...||

0||3||2 FE

||....||||||'

6

76

m

i

iVVVV

iF

v )(vd

represents the degree of nodes greater than 6. From (10.2.1) we induce that

(10.3.3)

We have

(10.3.4)

Merge (10.3.1) and (10.3.4) , we have

(10.3.1) multiplied by 2 and then merge (10.3.4) again, we obtain

(10.3.5)From Euler formula we know (10.3.5) is wrong, since . Thus we prove it is impossible that every degree of nodes is greater than 6 in simple planar graph.

||||2'

6

m

i

iViE

||6||6||2'

6

VVEm

i

i

'm

0||6||3||4

0|)|6||2(|)|3||2(

VFE

VEFE

0|)||||(|6||6||6||6|)|6||2(|)|6||4( VFEVFEVEFE

2 VFE

Example 2 Prove that there are at most edges in

simple planar graph G. Ans. From (10.3.1) we have

(10.3.6)

Substitute Euler formula into the left pattern of (10.3.6), we have

Thus, we prove that there are at most edges.

63 V

032 FE

EFE 3

FEV 2

)2(3 EV

EV 63

63 V

Example 3 Is a simple planar graph? Ans.

In , there are 10 edges, there are at most edges in

simple planar graph. Thus, is not a simple planar graph.

5K

5K 9653

5K

5KFig. 10.3.2

Example 3.1 For every tree , if , T has at least two pendant vertices . i.e. vertices of

degree 1. Ans.

(1) If T doesn’t have pendant vertices and T is connected graph, then , , and |E| = |V| 1, we have

Induce that , it is a contradiction.

(2) If T has one pendant vertices, then

Induce that , it is a contradiction.

Combine the discussion (1) and (2), thus T has at least two pendant vertices.

( , )T V E | | 2V

v V deg( ) 2v

2(| | 1) 2 | | deg( ) 2 | |v V

V E v V

2 0

2(| | 1) 2 | | deg( ) 2(| | 1) 1v V

V E v V

0 1

Example 3.2 Suppose G is an arbitrary digraph with n vertices. What is the largest possible number of distinct subgraphs with k vertices that G may have ? (Isomorphic subgraphs are distinct. Choose G to maximize this number.)

Ans. When G is a complete graph which the number of nodes is n, it will

have the largest possible number of distinct subgraphs. When the

number of nodes is k, there are at most edges, and these

edges have two choices : choose or not choose, it will compose all

the digraph, there are different digraph. There are choices

and we need to consider about which the number of nodes is k, thus

the answer = .

2

k

22k

n

k

22k

n

k

Graph Representation

Adjacency List

Adjacency Matrix

Example 4 What is the representation of adjacency list ?

Ans.

Fig. 10.3.3 A little example

1 2 4

2 1 3 4

3 2 4

4 1 2 3

Fig. 10.3.4 The representation of adjacency list

Example 5 What is the representation of adjacency matrix ?

Ans. The representation of adjacency matrix :

From above, the representation of adjacency matrix in figure 10.3.3 is

0111

1010

1101

1010

4

3

2

14321

M

1, if ( , )[ , ]

0, if ( , )

i j EM i j

i j E

Example 6 What the problem is Warshall algorithm used to solve ?

Ans.

If , but node i can reach node j through node k , we say that node i can reach node j and write down . As shown in Figure 10.3.5.

0, jiM 1, 2 jiM

2[ , ] 1M i j Fig. 10.3.5

represents that node I can reach node j through m edges.

Warshall algorithm is the check of reachability between any two nodes in graph G, that is to compute

(10.3.7)

Here, . We solve the transitive closure problem in graph G.

1, mjiM

21* MMM

MM 1

Let

Then we obtain

010

000

101

M

000

000

111

2 MMM

010

000

1112MM

Example7 Before introduce Warshall’s algorithm, can you use brute force method to obtain ?

Ans.A:=M

B:=A

for i=2 to (|V|-1)

begin

A:=AMB:=BA

end

It will take by brute force method. 4V

*M

Example8 What is Warshall method?

Ans.Warshall’s method is easy, the following is the three for loops included in Warshall’s method : B:=Mfor k=1 to |V| begin for i=1 to |V| begin for j=1 to |V|

B[i, j]=B[i, j](B[i, k]B[k, j]) endendThe above procedure only need time 3

V

10.4 Shortest path

Example1 How many types does the shortest path have ?

Ans.Let the source node in is S, and the target node is T. The four combinations of the shortest path are:

Fig. 10.4.1 four combinations of the shortest path

The symbol I denotes the set of inner nodes.

S T

1 S0 T0

2 I T0

3 S0 I

4 I I

Fig. 10.4.2 an example of a direct graph

The first type of the shortest path is the problem of walking from node 1 to node 6. Let I=4, then the second type of the shortest path is the problem of walking from node 4 to node 6.

1

2

43

5

6

3

2

7

1

42

5

2

1

3

Example2 How is Floyd-Warshall algorithm used to solve the fourth type of the all pairs shortest path problem? And what is its time complexity?

Ans. The fourth type of shortest path problem Floyd-Warshall algorithm is used to solve all pairs shortest path problem.

Let adjacency matrix is W, Floyd-Warshall algorithm can bedesigned as follow :

B:=Wfor k=1 to |V| begin

for i=1 to |V| begin for j=1 to |V| W[i, j]=min(W[i, j],W[i, k]+W[k, j]) end

endIts time complexity is . 3

V

Example3 Can Floyd-Warshall algorithm solve the all pairs shortest path problem in figure 10.4.2?

Ans.From figure 10.4.2, we can get the source adjacency matrix

is

Here, represents that node 1 and node 4 not connect each other. After running k=1, adjacency matrix not change, that is

0

302

10

401

250

7230

6

5

4

3

2

1

)0(W

1 2 3 4 5 6

4,10W

)0()1( WW

After running k=2, we obtain

0

302

10

34601

250

578230

6

5

4

3

2

1

)2(W

1 2 3 4 5 6

After running k=3, will change into

0

302

10

34601

250

568230

6

5

4

3

2

1

)3(W

1 2 3 4 5 6

)2(W

Here, pay attention !

. When we complete k=4, 5 and 6, finally we obtain

Thus, the solve of the all pairs shortest path in figure 10.4.2 hides in . For example : tells us, the shortest path between node 2 and node 6 is 2.

(3) 2 2 21,5 min [1,5], [1,3] [3,5] min(7,2 4) 6W W W W

0

302

10

34601

250

568230

6

5

4

3

2

1

)6(W

1 2 3 4 5 6

(6)W (6) 2,6 2W

Example4 How Dijkstra solve the all pairs shortest path problems?Ans.

Given fig. 10.4.3 :

Fig. 10.4.3 An example

A

B

C

D

E

3

5

4

1

1

2

3

Select node A and place it into Labeled Node Set (LNS), and the other four nodes B 、 C 、 D and E are placed into Unlabeled Node Set (UNS). Find the edge node set which connects LNS and UNS and denote it as (LNS, UNS). In the edge node set (LNS,UNS), we find the smallest weighted edge (A,C) and know its weighted edge value is 2. Fig. 10.4.4 is the present condition. Direct at node C in the figure, we record [A,2].

Fig. 10.4.4 The condition of LNS after include node C

Check the edges joined in LNS and UNS, then we discover that (A,B), (A,D), (C,B) and (C,D) is four edges to join LNS and UNS. We can calculate from figure 10.4.4

(10.4.1)Similar, can calculate

Choose node B! Then the record on node B of [C,3]. Figure 10.4.5 is a sketch map after adding node B.

( ) min( ( ) ( , ), ( , ))

min(2 1,4)

3

d B d C w C B w A B

( ) min( ( ) ( , ), ( , ))

min(2 1,3)

3

d D d C w C D w A D

Fig. 10.4.5 Adding B to LNS

A

B

C

D

4

1

1

2

3

E

3

LNS

]2,[A

]3,[C

And then, we choose node B. Fig. 10.4.6 is a sketch map of LNS adding node D. Finally, we choose edge (B,E ) and node E, then pursued the final result of the Fig. 10.4.7.

Fig. 10.4.6 Adding node D into LNS

A

B

C

D

E

3

5

4

1

1

2

3

]2,[A

]3,[C

]3,[C

LNS

Fig. 10.4.7 Final result

By Fig. 10.4.7, we can get the shortest path and the length of shortest path from node A to all other nodes.

Example5 What is the time complexity of Dijkstra algorithm in Example4?

Ans.As to any node in LNS, at least (|V|-k) edges can link to any

node in UNS. If consider all extreme point in LNS, then there are at most k(|V|-k) edges link between LNS and UNS. Time complexity is

(10.4.2)

1

2

1 1

3( )

V

k

V V

k k

T O k V k

O k V O k

O V

top related