* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Chapter 3 Digraphs and Tournaments Example Directed graph
Survey
Document related concepts
Transcript
Example Chapter 3 Digraphs and Tournaments 17/08/05 FM Dong, NIE 1 17/08/05 FM Dong, NIE Directed graph 2 Vertices and Arcs u 1. A directed graph can be obtained from a graph by giving every edge a direction. a 2. A directed graph is usually called a digraph. b v 1. A digraph consists of vertices and arcs. 2. An arc is an ordered pair of vertices, e.g, a = (u,v) and b = (v, u). 3. a and b are different arcs. 17/08/05 FM Dong, NIE 3 17/08/05 FM Dong, NIE Formal definition 4 Arcs u A directed graph D = (V, A) consists of two finite sets V and A, where v a If a = (u,v) is an arc of D, then (i) V is the vertex set, and (i) a is said to join u to v, (ii) A is the arc set, where each arc is an (ii)u is called the original, or the initial vertex, or the tail of a, ordered pair of vertices. (iii)v is called the terminus, or the terminal vertex, or the head of a. 17/08/05 FM Dong, NIE 5 17/08/05 FM Dong, NIE 6 Example The underlying graph 1. Given a digraph D, we can get a graph G from D by removing all the directions. 2. G is called the underlying graph of D. Terminus, terminal vertex or head Original, initial vertex or tail D 17/08/05 FM Dong, NIE 7 G 17/08/05 FM Dong, NIE Orientation of a graph 8 Example 1. Given a graph G, we can obtain a digraph D from G by specifying a direction for each edge of G. 2. Such a digraph D is called an orientation of G. One orientation of K3. How many orientations are there in K3? 17/08/05 FM Dong, NIE 9 17/08/05 FM Dong, NIE 10 Directed walks 3.2 Connectivity of digraphs 1. Let D be a digraph. 2. A directed walk in D is a finite sequence W = v0a1v1a2v2...akvk. a1 v0 17/08/05 FM Dong, NIE 11 17/08/05 a2 v1 … v2 v3 FM Dong, NIE ak vk 12 Example Directed trail, path and cycle. Find three different direct walks from v4 to v3. • A directed trail is a directed walk which does not repeat any arc. • A directed path is a directed walk which does not repeat any vertex, except the two ends. • A directed cycle is a directed path in which the two ends are the same vertex. v3 v4 a1 a6 a2 a7 a5 v1 v2 a4 a3 1 . v 4 a 7 v2 a 6 v3 2 . v 4 a 7 v 2 a 4 v1 a 3 v 2 a 6 v 3 3 . v 4 a 7 v 2 a 4 v1 a 5 v 2 a 6 v133 17/08/05 FM Dong, NIE 17/08/05 Exercise • Is it true that if there is a directed walk in D from x to y, then there is a directed path from x to y? True. Why? v3 v4 a6 a2 a7 a5 v1 v2 a4 14 Question Find all directed paths from v4 to v3. a1 FM Dong, NIE a3 1. v4a7v2a6v3 17/08/05 FM Dong, NIE 15 17/08/05 Weakly connected graph • Let u and v be vertices in D. • v is said to be reachable from u if there is a directed path in D from u to v. • D is said to be unilaterally connected if for every pair of vertices u and v, either u is reachable from v or v is reachable from u. v3 v4 a6 a2 a7 a5 v1 a4 16 Unilaterally connected • A digraph D is said to be weakly connected or connected if its underlying graph is connected. a1 FM Dong, NIE v2 a3 17/08/05 FM Dong, NIE 17 17/08/05 FM Dong, NIE 18 Exercise Theorem • A digraph D is unilaterally connected if and only if D has a spanning directed walk. • The sufficiency is obvious. Why? • Assume that P is a spanning directed walk in D. • For any two vertices u and v in D, they are both on P and so there is a directed walk from u to v or from v to u. • Thus D is unilaterally connected. • Draw a digraph D of order 5 such that D is weakly connected but not unilaterally connected. u v x w y Take u and w. u is not reachable from w and w is not reachable from u. Hence this digraph is not unilaterally connected. 17/08/05 FM Dong, NIE 19 Proof of Necessity • Suppose that D has no spanning directed walk. • Let P be a directed walk in D which contains the maximum number of vertices in D. • Denote the walk P by x1x2x3…xk. • D has a vertex, say w, which is not on P. 17/08/05 FM Dong, NIE • Since D is unilaterally connected, for every i=1,2,…, k, there is a directed walk P(xi,w) from xi to w or P(w,xi) from w to xi. w x1 x2 x21k FM Dong, NIE • There is no path P(w,x1); otherwise, D has a directed walk which contains more vertices than P, a contradiction. • So there is a directed walk P(x1,w). • Similarly, there is a walk P(w, xk). w 17/08/05 17/08/05 xk x2 P(w,xi) xk xi FM Dong, NIE 22 • Let s be the maximum number in {1,2,…,k} such that there is a directed walk P(xs,w) from xs to w. • We have 1 ≤ s < k. Why? • Then there is a directed walk P(w,xs+1) from w to xs+1. P(w,xk) P(w,x1) x1 x1 P(xi, w) xi w w x117/08/05 x2 20 x2 xk FM Dong, NIE 23 17/08/05 FM Dong, NIE 24 w P(xs,w) x1 xs x2 Strongly connected digraph P(w,xs+1) xs+1 xk • A digraph is said to be strongly connected if for every pair of vertices u and v in D, u is reachable from v and v is reachable from u. P2 P1 • Let P1 denote the directed walk on P from x1 to xs, let P2 denote the directed walk on P from xs+1 to xk. • Then P1,P(xs,w), P(w,xs+1) and P2 form a directed walk in D which contains more vertices than P, a contradiction. 17/08/05 FM Dong, NIE 25 •Hence the necessity holds. 17/08/05 Example 1. If u and v are in a directed closed walk, then v is reachable from u and u is reachable from v. 2. If v is reachable from u and u is reachable from v, then u and v are in the a directed closed walk. FM Dong, NIE 27 17/08/05 Example v 17/08/05 FM Dong, NIE 28 Theorem • A digraph is strongly connected if and only if it has a spanning closed walk. • The sufficiency is obvious. u FM Dong, NIE 26 Observations A strongly connected digraph 17/08/05 FM Dong, NIE 29 17/08/05 FM Dong, NIE 30 Example Homework Is this digraph strongly connected? • Prove this theorem. • Hint: apply the result for unilaterally connected digraphs: • Since D is strongly connected, D is also unilaterally connected and so D has a spanning directed walk. V2 V1 V10 V3 V4 V5 V7 V9 V8 V6 • It is not strongly connected. • It can be split into strongly connected subdigraphs. 17/08/05 FM Dong, NIE 31 17/08/05 FM Dong, NIE Strong component Exercise • A strong component of a digraph D is a subdigraph of D which is strongly connected and is not a proper subdigraph of any other strongly connected subdigraph of D. Find all strong components of the following digraph. 2 1 17/08/05 FM Dong, NIE 33 17/08/05 Observation FM Dong, NIE a2 a4 a3 a7 a1 5 a5 a6 3 4 FM Dong, NIE 34 3.3 Matrix representations • If two vertices are in a directed closed cycle, then the two vertices are in the same strong component. • If u is reachable from v and v is reachable from u , then u and v are in the same strong component. 17/08/05 32 35 1. Adjacency matrix 2. Incidence matrix 17/08/05 FM Dong, NIE 36 Definition Adjacency and incidence • Let u and v be vertices in a digraph. • If u and v are joined by an arc e, then u and v are said to be adjacent. • If the arc e is directed from u to v, then e is said to be incident from u and incident to v. e is incident from u and incident to v e u v u and v are adjacent e u 17/08/05 FM Dong, NIE 37 17/08/05 v FM Dong, NIE Degrees 38 Example v • Let D be a digraph and u be a vertex in D. • The out-degree of u is the number of arcs incident from u, and is denoted by od(u). • The in-degree of u is the number of arcs incident to u, and is denoted by id(u). w u x y z od(u)=1, od(v)=3, od(w)=2, od(x)=0, od(y)=1, od(z)=2 id(u)=0, id(v)=1, id(w)=1, id(x)=0, id(y)=5, id(z)=2 17/08/05 FM Dong, NIE 39 17/08/05 Observation 1 ∑ id ( x) = ∑ od ( x) = number of arcs in D FM Dong, NIE Col. Col. Col. Col. 1 2 3 4 2 x∈V Row 1 • Why? • Since each arc has two ends, it must contribute exactly 1 to the sum of the out-degrees and exactly 1 to the sum of in-degrees. The result follows immediately. 17/08/05 40 Adjacency Matrix • In any digraph, x∈V FM Dong, NIE 41 3 4 17/08/05 Row 2 Row 3 Row 4 FM Dong, NIE ⎛0 ⎜ ⎜0 ⎜0 ⎜ ⎜0 ⎝ 1 0 1 0 0 0 0 1 1⎞ ⎟ 2⎟ 0⎟ ⎟ 0 ⎟⎠ 42 Adjacency Matrix Exercise • Let D be a digraph with n vertices labeled 1,2,…,n. Find the adjacency matrix A(D) of the following digraph. • The adjacency matrix A(D) is the n×n matrix: 2 A ( D ) = (a i , j )n × n 5 1 ai,j = the number of arcs from i to j. 17/08/05 FM Dong, NIE 3 43 4 17/08/05 0 0 1 1 1 1 1 1 2⎞ ⎟ 3⎟ 0⎟ ⎟ 0 ⎟⎠ • Let D be a digraph and A(D)=(ai,j)n×n. • Then ∑a 4 1≤ j ≤ n i, j ∑a 1≤ i ≤ n 3 2 17/08/05 FM Dong, NIE = the out - degree of the i th vertex i, j ∑a 1≤ i ≤ n 17/08/05 1≤ j ≤ n 45 = the in - degree of j th vertex i, j = the number of arcs in D . FM Dong, NIE 1 2 • Let D be a digraph with vertices v1,v2,…,vn, and A(D) be the adjacency matrix of D. • If ( A( D) ) = (a ) k i , j n×n , ( A ( D ) )2 k FM Dong, NIE 47 ⎛0 ⎜ ⎜0 A(D ) = ⎜ 0 ⎜ ⎜0 ⎝ 3 4 then a i , j is the number of directed walks of length k from vi to vj for all i,j: 1≤i≤j≤n. 17/08/05 46 Example Theorem k 44 Numbers of arcs Find a digraph D such that its adjacency matrix is the following matrix. 1 0 0 0 0⎞ ⎟ 0 0 2 0⎟ 1 0 1 0⎟ ⎟ 0 0 0 1⎟ 0 1 0 0 ⎟⎠ FM Dong, NIE Exercise ⎛1 ⎜ ⎜0 ⎜0 ⎜ ⎜0 ⎝ ⎛0 ⎜ ⎜1 A(D) = ⎜ 0 ⎜ ⎜0 ⎜0 ⎝ 17/08/05 FM Dong, NIE ⎛0 ⎜ ⎜0 =⎜ 0 ⎜ ⎜0 ⎝ 1 0 1 0 0 0 0 1 1⎞ ⎟ 2⎟ 0⎟ ⎟ 0 ⎟⎠ 0 0 0 1 2 0 1 0 2⎞ ⎟ 0⎟ 2⎟ ⎟ 0 ⎟⎠ 48 By induction, Proof of Theorem a 1i, t = number of arcs from v i to v t a st, j = number of walks of length s from v t to v j • It holds if k=1, by the definition of A(D). • Assume that it holds when k≤s, where s≥1. Now let k=s+1. s +1 s • Observe that ( A( D) ) = A( D) × ( A( D) ) , (a ) s +1 i , j n×n i.e., ( ) × (a ) = ai1, j n×n s i , j n×n Thus n ais,+j1 = ∑ ( number of arcs from v i to v t ) t =1 . × (number of walks of length s from v t to v j ) = the number of walks of length s + 1 from vi to v j . n ais,+j1 = ∑ ai1,t × ats, j . So t =1 17/08/05 FM Dong, NIE 49 Hence for NIE k=s+1. 17/08/05 the theorem holds FM Dong, Incidence Matrix v1 a1 a5 a4 a6 v4 17/08/05 a3 a2 v3 Incidence Matrix Col. Col. Col. Col. Col. Col. 3 5 6 4 2 1 v2 Row 1 ⎛ 1 0 0 1 ⎜ Row 2 ⎜−1 −1 0 0 Row 3 ⎜ 0 1 −1 0 ⎜ ⎜ Row 4 ⎝ 0 0 1 −1 0⎞ ⎟ 1⎟ 0 0⎟ ⎟ −1 −1⎟⎠ 0 1 FM Dong, NIE 51 • The incidence matrix involves the incidence of vertices and arcs. • Let D be a digraph without loops, with n vertices labeled v1, v2,…,vn, and m arcs labeled a1, a2,… ,am. 17/08/05 if arc a j is incident from vertex vi ; if arc a j is incident to vertex vi ; otherwise. FM Dong, NIE 52 Find the incidence matrix I(D) of the following digraph D. 2 a2 5 a5 a4 a3 a7 a6 1 17/08/05 FM Dong, NIE Exercise • The incidence matrix I(D) is the n×m matrix in which the entry in row i and column j is ⎧1, ⎪ ⎨- 1, ⎪ ⎩0, 50 53 17/08/05 3 a1 FM Dong, NIE 4 54 Exercise 0 0 −1 0 0 0⎞ ⎛ 0 ⎜ ⎟ 1 1 1 0 0 − 1⎟ ⎜ 0 ⎜ 1 0 0 0 −1 0 1⎟ ⎜ −1 −1 −1 0 0 1 0⎟ ⎜⎜ ⎟⎟ 0 1 0 0 0 0 − 1 ⎝ ⎠ 17/08/05 FM Dong, NIE Find a digraph D such that its incidence matrix is the following matrix. ⎛ 1 ⎜ ⎜−1 ⎜ 0 ⎜ ⎜ 0 ⎝ 55 17/08/05 3.4 Acyclic digraph a1 v4 17/08/05 a3 FM Dong, NIE a2 v3 57 Two cases: y z … x 17/08/05 y FM Dong, NIE 1 0 −1 0 2 4 3 FM Dong, NIE 56 17/08/05 FM Dong, NIE 58 • If z is on P(x,y), then one directed cycle C can be formed by the arc yz and the path P’(z,y) from z to y which is on the path P(x,y), a contradiction. • Hence Z is not on P(x,y). • Thus the P(x,y) can be extended to a longer path from x to z: P(x,y)z, contradicting the assumption that P(x,y) is a longest path in D. • Therefore od(y)=0. … x 1 1 • Proof. Let P(x,y) be a longest path in D, which is from x to y. • It is clear that x≠y. • We shall show that od(y) = 0. • Suppose that od(y)>0. Let yz be an arc in D. v2 a6 0 0 ⎞ ⎟ 0 ⎟ 1 ⎟ ⎟ − 1 ⎟⎠ • An acyclic digraph D has at least one vertex of out-degree 0. a5 a4 0 Theorem • A digraph is called acyclic if it contains no directed cycles. • The following digraph is acyclic. v1 −1 59 17/08/05 FM Dong, NIE 60 Theorem Example • An acyclic digraph D has at least one vertex of in-degree 0. v1 a1 v2 a5 a4 v4 od (v4 ) = 0 17/08/05 FM Dong, NIE 61 17/08/05 a5 x4 17/08/05 xFM2 Dong, NIE ⎛0 ⎜ ⎜0 ⎜0 ⎜ ⎜0 ⎝ 0 1 0 1 0 0 0 0 1⎞ ⎟ 1⎟ 2⎟ ⎟ 0 ⎟⎠ 63 17/08/05 FM Dong, NIE 64 • Let D’=D-x. • It is clear that D’ is acyclic. • As the order of D’ is n-1 =k, by induction, there is an ordering x2,x3,…,xn of vertices in D’ such that the adjacency matrix M’ of D’ is upper triangular. • Since id(x1)=0, the adjacency matrix M of D is ⎛ 0 a1, 2 a1,3 ... a1,n ⎞ • We shall prove by induction on the order n of D. • If n=1, the result holds. • Assume that the result holds if n=k, where k≥1. • Now let n = k+1. • Since D is acyclic, D has a vertex x with id(x)=0. • Let x1=x. FM Dong, NIE 62 The following statements are equivalent: (1) D is acyclic; (2) Every walk is a path; (3) It is possible to order the vertices in D such that A(D) is upper triangular. Prove that (1) ⇒ (3). 17/08/05 id (v1 ) = id (v3 ) = 0. Theorem • The following digraph D is acyclic . • Can you find an order of the vertices in D such that A(D) is upper-triangular? How? x3 v3 a3 FM Dong, NIE Example x1 a2 a6 ⎜ 0 M =⎜ ⎜M ⎜ ⎝0 65 M' Hence M is upper triangular. 17/08/05 FM Dong, NIE ⎟ ⎟ ⎟ ⎟ ⎠ 66 Algorithm Algorithm • Let D=(V,A) be an acyclic digraph. We shall find an ordering of vertices in D such that its adjacency matrix is upper-triangular. 17/08/05 FM Dong, NIE 67 • D =(V, A) is an acyclic digraph. • • • • • • Step 1: S := ∅ and s:=0. Step 2: H:=D-S. Step 3: Choose a vertex w in H with idH(w)=0. Step 4: s:=s+1 and xs :=w; Step 5: If s=|V|, then stop. Step 6: S:=S∪{xs}. Go to step 2. 17/08/05 FM Dong, NIE 68 3.5 Tournaments Theorem 3.5.1 • A tournament is a digraph whose underlying graph is a complete graph. • The following digraph is a tournament on 4 vertices. • Let D be a tournament and x be a vertex in D which has the maximum out-degree. • Then for any vertex y in D, there is a directed path from x to y of length at most 2. 17/08/05 FM Dong, NIE 69 Proof • Let x1,x2,…,xk be the vertices in D which x is adjacent to. So od(x) = k. • If y is some vertex xi, then xy is a directed path. 17/08/05 … y x x1 17/08/05 x … x2 FM Dong, NIE 70 • Now assume that yx is an arc. • There must be some xi such that xiy is an arc in D. • Otherwise, yxi is an arc in D for all i=1,2,…,k, implying that od(y)>k, contradicting the assumption that x has the maximum out-degree. • Thus xxiy is a path of length 2. … y FM Dong, NIE xk x1 71 17/08/05 … x2 FM Dong, NIE xk 72 Theorem 3.5.2 Theorem 3.5.2 • Any tournament D has a spanning directed path. • Proof. • For every pair of vertices x and y, either xy or yx is an arc. • Thus D is unilaterally connected. • Hence D has a spanning directed path. • If D is a strongly connected tournament of order n, then D contains a directed cycle of length k for all k=3,4,…,n. 17/08/05 17/08/05 FM Dong, NIE 73 • First show that D has a directed cycle of order 3. • Let x be any vertex in D. • Let A = {w∈V(D): (w,x) is an arc in D}. • Let B = {w∈V(D): (x,w) is an arc in D}. • Since D is strongly connected, both A and B are not empty. x FM Dong, NIE A B 75 • Now we show that if D has a directed cycle of order k, where 3≤k≤n-1, then D has a directed cycle of order k+1. 74 • Since D is strongly connected, there must be one arc (y,z), where y∈B and z∈C. • Thus xyzx is a directed cycle of order 3. y … z … 17/08/05 … … A FM Dong, NIE x 17/08/05 FM Dong, NIE B 76 • Case 1: D contains a vertex w not on C such that ( w, x ) ∈ A( D ), ( y , w) ∈ A( D ) for some x, y on C • Denote the cycle C by x1x2…xkx1 with the direction x1→x2 → …→xk→ x1. • Assume that (x1,w) is an arc in D. C x1 17/08/05 FM Dong, NIE 77 17/08/05 W FM Dong, NIE 78 • Since (w,x) is an arc in D for some vertex x in C, there exists the minimum integer in {1,2,…,k} such that (w,xi) is an arc in D. • It is clear i>1. Then (xi-1,w) is an arc in D. • Thus we have a cycle of order k+1: • Case 2: for every vertex w not on C, either (w,x) is an arc for all vertices x on C, or (x,w) is an arc for all vertices x on C. Let A1 = {w ∈V ( D) / V (C) : (w, x) ∈ A( D) for all x in V (C)}. A2 = {w ∈V ( D) / V (C) : ( x, w) ∈ A( D) for all x in V (C)}. x1 L x i −1 wx i L x k x1 . C C xi-1 xi x1 W 17/08/05 FM Dong, NIE 79 • Since D is strongly connected, both A1 and A2 are not empty. • Again since D is strongly connected, there must be an arc (y,z) in D, where y∈A2 and z∈A1. 17/08/05 A1 FM Dong, NIE A2 80 • Then the following cycle is of order k+1: x1 yzx 3 L x k x1 . • This completes this proof. C A1 17/08/05 y z A2 FM Dong, NIE 81 17/08/05 Theorem 3.5.3 FM Dong, NIE 82 End • A tournament of order n is strongly connected if and only if D has a directed cycle of order n, where n>2. 17/08/05 FM Dong, NIE 83 17/08/05 FM Dong, NIE 84