Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics Transparency No. 9-1 Chapter 9 Graphs.

Similar presentations


Presentation on theme: "Discrete Mathematics Transparency No. 9-1 Chapter 9 Graphs."— Presentation transcript:

1 Discrete Mathematics Transparency No. 9-1 Chapter 9 Graphs

2 Discrete Mathematics Chap 9 Graphs Transparency No.9-2 Chapter 9. Graphs Old subject with many modern applications Introduced by L. Euler, who used it to solve the famous Konisberg bridge problem. Example applications: determine if a circuit can be implemented on a planer circuit board (planer graph) distinguish b/t two chemical compounds with the same molecular formula but with different structures. determine if two computers are connected in a network. schedule (with task precedence information given, find an execution plan.)..

3 Discrete Mathematics Chap 9 Graphs Transparency No.9-3 table of contents Introduction Graph terminology Representing graph and graph isomorphism Connectivity Euler and Hamilton paths Shortest path problems Planer graphs Graph coloring

4 Discrete Mathematics Chap 9 Graphs Transparency No Introduction Graph: discrete structure consisting of vertices and edges that connect these vertices. Types of graphs: simple graph: G=(V,E) where E is a set of unordered pairs of distinct elements of V. multi-graph: allow multiple edges b/t two distinct vertices. pseudograph: allow self-loop and multiple edges digraph (directed graph): edges are ordered pairs of vertices. Directed multigraph: allow multiple edges b/t any two (possibly identical) vertices. Hybrid Graph: allow both directed and undirected edges. Weighted (or labeled) graph: Each edge is associated with a weight (or a label).

5 Discrete Mathematics Chap 9 Graphs Transparency No.9-5 Formal definitions Def 2: (multigraph) G=(V,E,f) where f: E-> {{u,v} | u,v  V and u  v} with f(e) containing the two vertices the edge e is connected to. If f(e1) = f(e2) ==> e1 and e2 are parallel or multiple edges. Def 3: A pseudo graph G = (V,E,f) where f: E -> {{u,v} | u,v  V}. Note: if f(e) = {u} ==> e is a self-loop on u. Note: If there is no worry of confusion, we usually use {u,v} to identify the edge e with f(e) = {u,v}. Def 4: a digraph G=(V,E) where E is a subset of V 2. Def 5: A directed multigraph G=(V,E,f) where f: E -> V 2. If f(e1) = f(e2) ==> e1 and e2 are parallel or multiple edges. note: f(e1) = (u,v) /\ f(e2) = (v,u) /\ u  v => e1 and e2 are not parallel edges.

6 Discrete Mathematics Chap 9 Graphs Transparency No.9-6 Labeled (or weighted) grapgh A labeled graph G = (V,E,f, L, l) where (V,E,f) is a graph of any kind (without labeling), L is the set of labels, and l: E->L is the labeling function. if f(e) = w, we say e is an w- labeled edge or simply an w-edge. Hyper graph: edges can connect more than 2 vertices: e.g hyper k-graph G=(V,E,f) where f:E-> V k. Summary: type directed edge? multiedge? loop? simple nonono multigraph noyesno pseudonoyesyes digraphyesnoyes directed- yesyesyes -multigraph

7 Discrete Mathematics Chap 9 Graphs Transparency No.9-7 Graph models Ex1: Niche overlap graphs in ecology: G=(V,E) is a simple graph where V is the set of species. {u,v}  E iff u and v compete for food. Ex2:V: Persons (u,v)  E iff u can influence v. =>Influence graph: (digraph) (u,v)  E iff u, v know each other=> Acquaintance graph (undirected graph) Ex3: Round-Robin Tournaments One where each team plays each other team exactly once. V: the set for all teams (u,v) in E iff team u beats team v. Ex: 4-team Round-Robin tournament A D C B

8 Discrete Mathematics Chap 9 Graphs Transparency No.9-8 Graph model (cont'd) Ex 4: (precedence graph and concurrent processing) eg: 1. x := y +1; 2. z := f(x) => (1) must be executed before (2) no matter which processors execute (1) or (2), since (2) must use the execution result of (1). The executed-before relation in a program can be represented by a digraph G=(V,E) where V= the set of statements in the program (u,v)  E means u must be executed before v. note: if (u,v) and (v,w)  E, ==> (u,w)  E. Hence E is transitive.

9 Discrete Mathematics Chap 9 Graphs Transparency No.9-9 Precedence graph of a program Ex 4: s1: a := 0; s2: b := 1; s3: a := a+1; s4: d:= b+a; s5: e := d+1; s6: e := c+d ==> What is the precedence graph of this program? s1 s3 s5 s2 s4 s6

10 Discrete Mathematics Chap 9 Graphs Transparency No.9-10 Precedence graph of a program Ex 4: s1: a := 0; s2: b := 1; s3: a := a+1; s4: d:= b+a; s5: e := d+1; s6: e := c+d ==>Problems: 1. Minimum time needed to complete the program using multiple processors? (Depth) => length of longest paths Minimum # of processors needed to complete the program in minimum time ? (Width) => p1: [s1,s3,s4,s6], p2:[s2,-,-,s5] s1 s3 s5 s2 s4 s6

11 Discrete Mathematics Chap 9 Graphs Transparency No Graph terminology Def 1: G = (V,E) : undirected graph if u --e-- v ==> u and v are adjacent (or neighbors) Edge e is incident with u (& v). e connects u and v. u and v are end points of e. Def 2: G=(V,E): undirected graph; v  V ==> [degree of v:] deg(v) = #edges incident with it = |{e | v is an end point of e and e is an edge}|. If deg(v) = 0 ==> v is isolated. If deg(v) = 1 ==> v is pendant (or hang). Ex: In Fig 1, E has degree 3, D is pendant and G is isolated. G EF D CB A

12 Discrete Mathematics Chap 9 Graphs Transparency No.9-12 Handshaking theorem Theorem 1: G = (V,E) : a undirected graph ==>  v  V deg(v) = 2 |E|. // 插孔數 = 插頭數 pf: Simple induction on the number of edges |E|. (Intuition: vertex deg = socket, edge end = plug ) Ex: G=(V,E) with |V|=10 & each vertex with degree 6. ==> |E| = ? Corollary: The sum of the degrees of the vertices of an undirected graph is even. Theorem 2: The number of vertices in a graph with odd degree is even. pf:  v in V deg(v) =  v in V /\ deg(v) is odd deg(v) +  v in V /\ deg(v) is even deg(v) ==>  v in V /\ deg(v) is odd deg(v) is even ==> |{v in V | deg(v) is odd}| is even. QED

13 Discrete Mathematics Chap 9 Graphs Transparency No.9-13 Terminology for digraphs Def 3: G=(V,E): a digraph if u --e--> v then u is adjacent to v v is adjacent from u u is the initial (or starting) vertex of e v is the end (or terminal) vertex of e e is an edge from u to v. Def. 4: [in-degree; out-degree] In-deg(v) = #edge coming into v = |{ e  E | v is the terminal vertex of e}|. out-deg(v) = #edge going out from v = |{ e  E | v is the starting vertex of e}|. Theorem 3:  v in V in-deg(v) =  v in V out-deg(v) = |E|.

14 Discrete Mathematics Chap 9 Graphs Transparency No.9-14 underlying undirected graph G = (V,E,f) : a directed graph ==> Its underlying undirected graph is a pseudo graph G'=(V,E,f') where f':E -> {{u,v} | u,v  V} s.t. f'(e) = {a,b} iff f(e) = (a,b). Note: 1. Both G and G' has the same number of edges (= |E| ). 2. If both (u,v) and (v,u) are edges in G ==> (u,v) and (v,u) are two distinct edges in G'. Ex: G=({1,2,3}, {(1,2),(1,2),(1,3),(2,3),(3,2)}) ==> G' = ?

15 Discrete Mathematics Chap 9 Graphs Transparency No.9-15 Special simple graphs Ex 4: complete graphs K n = (V,E) where |V|= n and E = {{x,y} | x and y are distinct vertices of V}. Ex: K 1,..., K 5 = ? Ex 5: Cycles: C n (n >2) = (V, E) where V = {1,2,..., n} and E = {{i, i+1} | i = 1,..., n-1} U {{n, 1}}. Ex: C 3,C 4,C 5,C 6 = ? Ex 6: wheels: (n > 2) W n = (V,E) where V = {0,1,...,n} and E = {{0, i } | i = 1,...,n} U {{i,i+1} | i = 1,...,n-1} U {{n,1}}. W 3,W 4,W 5 = ? Ex7: n-cubes Q n = (V,E) where V = {0,1} n is the set of all bit strings of length n and E ={{x,y} | x and y differ at exactly one position.} Ex: and is connected. Ex: Q 1, Q 2, Q 3, Q 4 = ?

16 Discrete Mathematics Chap 9 Graphs Transparency No.9-16 Bipartite Graphs Def 5: G = (V,E) is bipartite iff there is a binary partition {V 1,V 2 } of V s.t. for all e  E, one end point of E is in V1 and the other end point is in V2. Ex8: Is C 6 bipartite ? (yes! why?) Ex9: Is K 3 bipartite ? (no! why ?) Ex10: Which of Fig G and H is bipartite ? Ex11: K m,n (complete bipartite graph) K m,n = ({u 1,...,u m } U {v 1,...,v n }, E}, where E = {{u i, v j } | i=1..m v = 1..n} eg: K 2,3, K 3,3 = ? problem: K m,n has ? edges f e a b d c H f g ab c d e G

17 Discrete Mathematics Chap 9 Graphs Transparency No.9-17 Ex 13: interconnection network for processors Types of connections Linear array: mesh Hyper cube (m-cube) Main measures: 1. #links 2. longest distance linear array n-1 n-1 mesh 2sqrt(n)(sqrt(n)-1) 2(sqrt(n) -1) m-cube(n=2 m ) nm/2 = O(n lg n) m = lg n

18 Discrete Mathematics Chap 9 Graphs Transparency No.9-18 New graphs from old Def 6: [subgraph] G=(V,E): a graph H= (V',E') is a subgraph of G iff V'  V and E'  E and H is a graph (i.e., if e  E' is an edge connecting u and v in V, then u, v must belong to V'.) Ex: G= K 5 ; find a subgraph H of K 5. Def 7: [union of simple graphs] G1=(V1,E1); G2=(V2,E2): two graphs. ==> G1UG2 = def (V1 U V2, E1U E2) Note: Not only V1 and V2, but also E1 and E2 may overlap. Ex:G1 = ({a,b,c,d,e}, {ab,bc,ce,be,ad,de}) G2 = ({a,b,c,d,f}, {ab,bc,bd,bf}} ==> G1 U G2 = ? Def 7' : Disjoint union of graphs: Disjoin union of G1 and G2 = ?

19 Discrete Mathematics Chap 9 Graphs Transparency No Graph representation and Graph isomorphism Graph representation : [suitable only for finite graphs] adjacent list (for graphs w/o multiple edges) :O(|E|+|V|) adjacent matrices: O(|V| 2 ) incident matrices (or list) : O(|V|x|E|). adjacent list: for each vertex v, a[v] is the list of all vertices adjacent with/from v. adjacent matrix: M[u,v]=1 iff {u,v} (or (u,v) if directed) is an edge. incident matrix: I[u,e] = 1 iff u  f(e), or (for directed graph) i[u,e]= 1 (or -1) iff u is the starting (or ending) vertex of e. Ex: (P612 Fig1&Fig2)

20 Discrete Mathematics Chap 9 Graphs Transparency No.9-20 Graph isomorphism Def. 1: G1=(V1,E1), G2=(V1,E2): two simple or digraphs G1 and G2 are isomorphic iff  a bijection h:V1->V2 s.t. for all u,v in V1, {u,v} (or (u,v))  E1 iff {h(u),h(v)} (or (h(u),h(v)))  E2. Such h is called an isomorphism (b/t G1 and G2). Ex 8: Are G = ({1234}, {12,23,34,41}) and H=({abcd},{ad,ac,bc,bd}) isomorphic ? Fact: If G1 and G2 are isomorphic ==> |V1|=|V2| & |E1|=|E2|. and G1 and G2 has the same degree type. Def: For each G=(V,E), type(G) is the multiset {deg(v) | v  V}.

21 Discrete Mathematics Chap 9 Graphs Transparency No Connectivity Def 1: G = (V,E,f): an undirected multi-graph A path  of length n > 0 from u to v is a sequence of edges e 1, e 2,...,e n s.t. f(e 1 ) = {u,x 1 }, f(e 2 ) = {x 1,x 2 },…,f(e n ) = {x n-1,v}. e 1 e 2 e 3 e 4 e 5 e 6 e n-1 e n u=x x x x x x ….----x n x n =v If G is a simple graph ==>  can be identified by the sequence of vertices: x 0 =u, x 1,..., x n-1, x n = v.  is a circuit (or cycle) iff x 0 = x n.  is simple if all edges in the path are distinct (i.e., for all 0≤ i

22 Discrete Mathematics Chap 9 Graphs Transparency No.9-22 Connectivity (cont'd) Def. 2: G = (V,E,f): a directed multigraph A path  of length n > 0 from u to v is a sequence of edges e 1, e 2,...,e n s.t. f(e 1 ) = (u,x 1 ), f(e 2 ) = (x 1,x 2 ),...f(e n ) = (x n-1,v). If G is a digraph ==>  can be identified by the sequence of vertices: x 0 =u, x1,..., x n-1, x n = v.  is a circuit (or cycle) iff x 0 = x n.  is simple if all edges in the path are distinct (i.e., for all 0

23 Discrete Mathematics Chap 9 Graphs Transparency No.9-23 Theorem about simple paths Theorem 1: There is a simple path between every pair of distinct vertices of a connected undirected [multi-]graph. Pf: (u,v): any two distinct vertices of G. Since G is connected, there exist paths from u to v. Let  = e 1,e 2,...,e n be any path of least length from u to v. Then  must be a simple path. If it were not, then there would be 0  i the path  = e 1,..,e i-1,e j+1,..,e n or e 1,..,e i,e j+1,..,e n is another path from u to v with length < |  |, a contradiction!. QED ux1x2 x i-1 xi x j-1 xjx j+1 v e1e2eiei ejej e j+1 reaching x i-1 means reaching x j if x i-1 = x j reaching x i means reaching x j if x i = x j

24 Discrete Mathematics Chap 9 Graphs Transparency No u x1x2 x i-1 xixi x j-1 xjxj x j+1 v e1e2 eiei ejej e j u x1x2 x i-1 xixi xjxj x j-1 x j+1 v e1e2 eiei ejej e j+1

25 Discrete Mathematics Chap 9 Graphs Transparency No.9-25 A theorem about simple circuits G=(V,E) : a undirected multi-graph, u,v: two vertices in G. Theorem: if there are two distinct simple paths from u to v, then there is a simple circuit in G. Pf:Let  1 : x 0 --(e1)-- x 1 --(e2)-- x 2 --(e3)--…--(e t )--x t --(e t+1 )--x t+1 --…---x n =v, and  2 : x 0 --(e1)-- x 1 --(e2)-- x 2 --(e3)--…--(e t )--x t --(e’ t+1 )--y t+1 --…---y m =v, be two distinct simple paths fro u to v in G, if either  1 or  2 contains a (simple) circuit, then we are done. Otherwise let e t+1, e’ t+1 the first edges with e t+1 ≠e’ t+1. let J be the least number in {t+1,…,m} such that y J = x s where s is any vertex occurring in path  1 (I.e., y J =x s ∈ {x 0,…,x n }). Note since y m = x n = v, such J must exist.

26 Discrete Mathematics Chap 9 Graphs Transparency No.9-26 A theorem about simple circuits Now it is easy to see that: 1. if s ≤ t then { x s --(e s+1 )-- x s+1 --…--(e t )—x t } U { x t --(e’ t+1 )--y t+1 --…--(e’ J-1 )-y J } is a circuit. This is not possible since all edges of the circuit are part of  2, but  2 is assumed to have no simple cycle. 2. If s > t then {x t --(e t+1 )--x t+1 --…-(e s-1 )--x s } U { x t --(e’ t+1 )--y t+1 --…--(e’ J-1 )-y J } ---(*) is a simple circuit. Note: {x t,x t+1,…,x s } ⋂ {x t,y t+1,…,y J } ={x t, y J =x s } if there were e a = e’ b => f(e a ) = {x t, x t+1 =x s } = {x t,y t+1 =y J } => a=b=t+1 => e t+1 = e’ t+1 a contradiction! o/w, by def, (*) is a simple circuit.

27 Discrete Mathematics Chap 9 Graphs Transparency No.9-27 XtXt e t+1 e’ t+1 eses e’ J xsxs yJyJ xsxs yJyJ y J-1 u v

28 Discrete Mathematics Chap 9 Graphs Transparency No.9-28 Connected Components G=(V,E): a undirected graph; 1. Any maximal connected subgraph of G is called a connected component of G. (i.e., G'=(V',E') is a connected component of G iff 1. G' is a connected subgraph of G and 2. There is no connected subgraph of G properly covers G'.) Ex:

29 Discrete Mathematics Chap 9 Graphs Transparency No.9-29 Connected components (cont'd) Note 1. Every two distinct connected components are disjoint. Pf: G1=(V 1,E 1 ), G2=(V 2,E 2 ): two distinct connected components. If G 1 and G 2 overlap (i.e., V 1  V 2  ). ==>  v ∈ V 1  V 2 ==> G 3 = (V 1 ⋃ V 2,E 1 UE 2 ) is a connected subgraph larger than G 1 and G 2, a contradiction! QED Note 2. Every connected subgraph G' of G must be contained in some connected component of G.

30 Discrete Mathematics Chap 9 Graphs Transparency No.9-30 Connected components (cont'd) Pf: Let i = 0 and G i = G'. If G i is maximal then we are done. o/w, there is connected G i+1 properly contains G i. If G i+1 is maximal, then we are done; o/t let i = i+1 and repeat the same process, we will eventually (if G is finite) get a maximal graph containing G'. Note: 3. Let G 1,G 2,...,G k be the set of all connected components of G. Then G = U i = 1..k G i pf: 1. U i=1,k G i  G since every G i  G. 2. G  U i=1,k Gi since every edge and every vertex must belong to some connected component.

31 Discrete Mathematics Chap 9 Graphs Transparency No.9-31 connected components (cont'd) Note 4: Every undirected graph G has a unique set of connected components. Pf: Let G = (V,E). For each vertex u in V, let G u = (V u,E u ) where V u = {v | there is a path from u to v}  V, and E u = {e | f(e)  V u }  E. It is easy to show that G u is a connected component of G. Moreover, we have 1. for all u, v ∈ V: G u = G v iff V u =V v /\ E u =E v and 2. for all e ∈ E: if f(e) = {u,v} ==> G u =G v and e  E u. Hence the set of connected components of G = {G u | u  V}. Note: Connected components in graphs play a role like equivalence classes in equivalence relations.

32 Discrete Mathematics Chap 9 Graphs Transparency No.9-32 The connectivity relation in a graph G=(V,E) : an undirected graph Let ~ be the connectivity relation induced by G, i.e., for all u,v in V, u ~ v iff either u = v or u and v are connected in G. Theorem: 1. ~ is an equivalence relation on V. (Hence V/~ is a partition of V) 2. For all u,v in V, u and v are connected iff u and v are in the same block of the partition. 3. For each u  V, G u = (V u,E u ) = ([u] ~, E| [u] ) where E| S is the set of edges restricted to the vertex set S, i.e., {e  E | f(e)  S}. 4. The set of all connected components of G = { (S, E| S ) : S  V/~}.

33 Discrete Mathematics Chap 9 Graphs Transparency No.9-33 cut vertices and cut edges A vertex in a graph is called a cut vertex (or articulation point) if the removal of this vertex and all edges incident with it will result in more connected components than in the original graph. Corollary: The removal of a cut vertex (and all edges incident with it) produces a graph that is not connected. Cut edges (bridges) The removal of it will result in graph with more connected components. Ex 4: Determine all cut vertices and all bridges in the right graph. cut vertices = ? bridges = ? ce a b d fg h

34 Discrete Mathematics Chap 9 Graphs Transparency No.9-34 Strongly connected digraphs Def 4: G=(V,E): a directed graph G is strongly connected iff there are paths from u to v and from v to u for every pair of distinct vertices u and v in G. Def 5: G is weakly connected iff there is a path between every pair of distinct vertices in G. Ex 5: G H G is strongly connected. H is weakly connected.

35 Discrete Mathematics Chap 9 Graphs Transparency No.9-35 Path and isomorphism P(-) : a property on graphs Ex: P(G) = "G has a simple cycle of length > 2" P(G) = " G has an even number of vertices and edges". P(G) =... P is said to be an isomorphic invariant if P is invariant under all isomorphic graphs, i.e., for all graph G 1 and G 2, if G 1 and G 2 are isomorphic then P(G 1 )  P(G 2 ). Ex1: P m,n (G) = " G has m vertices and n edges ", where m and n are some constant numbers, is an isomorphic invariant. Corollary: G 1,G 2 : two graphs; P: an isomorphic invariant; If P(G 1 ) and P(G 2 ) have distinct truth value, then G 1 and G 2 are not isomorphic.

36 Discrete Mathematics Chap 9 Graphs Transparency No.9-36 More on graph isomorphism Ex2: P2(G) = "G has a simple circuit of length k", where k is a number > 2, is an isomorphic invariant. pf: G1 = (V1,E1), G2 = (V2,E2): two simple graphs. Let h:V1->V2 be any isomorphism from G1 to G2. Then if x 0 --(e1)--> x 2 --(e2)--> x >(en)-->x n is a simple path on G1, then the sequence h(x 0 ) -->(h(e1))-->h(x 2 )--(h(e2))-->h(x 3 ) >((h(en))-->h(x n ) is also a simple path on G2. Ex 6: G and H are not isomorphic since H has s simple cycle of length 3 (1261), whereas G has no simple cycle of length GH

37 Discrete Mathematics Chap 9 Graphs Transparency No.9-37 Counting paths b/t vertices G=(V,E) with V={V 1,...,Vn} : a simple graph with adjacent matrix M. ==> # different paths of length k from v i to v j =(M k ) ij, where scalar multiplication are integer product (instead of boolean AND). Pf: by math ind on k. 1. basis step: k = 1: => By def. M ij is the number of edges (= path of length 1) from v i to v j. 2. Ind. step: assume (M m ) ij = #paths of length m from v i to v j for all m < k and for all u i, u j ∈ V. But #paths of length k from v i to v j = #paths of length k-1 from u i to v 1 x #paths of length 1 from v 1 to v j + #paths of length k-1 from u i to v 2 x #paths of length 1 from v 2 to v j #paths of length k-1 from u i to v n x #paths of length 1 from v n to v j =  t=1..n (M k-1 ) it x M tj = (M K ) ij.

38 Discrete Mathematics Chap 9 Graphs Transparency No.9-38 Example Ex 8: G=({1,2,3,4}, {12,13,24,34}) ==> M = [0110;1001;1001;0110] ==> M 4 = [8008;0880;0880;8008] ==> there are 8 different paths of length 4 from a to d. Notes: 1. The length of the shortest path from v i to v j is the least k s.t. (M K ) ij != G is connected if (  k=1..n-1 M k ) ij != 0 for all 1≤ i for any i ≠ j, there is a simple path (of length t < n) from v i to v j ==> (M t ) ij > 0 ==> (  k=1..n-1 M k ) ij != 0. QED

39 Discrete Mathematics Chap 9 Graphs Transparency No Euler and Hamilton paths The seven bridges problem: Problem: Is there a path passing through all bridges w/o crossing any bridge twice? Multigraph model: problem: Is there a simple path of length 7 ? The town of Konigsburg A B C D B C D A

40 Discrete Mathematics Chap 9 Graphs Transparency No.9-40 Eular paths and Eular cycles Def. 1: An Eular path in a multigraph G is a simple path containing all edges. Def. 2: An Eular circuit in a multigraph G is a simple circuit containing all edges. Ex1: In G1,G2 and G3: G1 has a Eular circuit:a,e,c,d,e,b,a. G3 has a Eular path: bedbadca. Note: If there is a Eular circuit beginning from a vertex v, then there is a Eular path or circuit beginning from any other vertex. G1G2G3 ab cd e ab c d e ab c d e

41 Discrete Mathematics Chap 9 Graphs Transparency No.9-41 Necessary and sufficient conditions for Eular path and Eular circuit Theorem 1: A connected multigraph has an Eular circuit iff each of its vertices has even degree. Corollary: The seven-bridges problem has no Eular circuit. pf: "=>": G=(V,E): any multigraph. Let  = x 0 e 1 x 1 e 2 x 2 e 2 x 3... e n x n =x 0 be any Eular circuit. For each v=x i in V ≠ x 0, since e i -->x i --> e i+1 we have deg(v) = 2 |{j | x j = v and 00. (its existence will be shown later.) If  is an Eular circuit, then we are done. O/W:

42 Discrete Mathematics Chap 9 Graphs Transparency No.9-42 Proof of Eular condition Let G' = (V',E') be the resulting graph formed from G by removing all e 1,e 2,...,e n from E. Let G 1 =(V 1,E 1 ),...,G k =(V k,E k ) be all connected components of G'. Since G is connected, {x 0,...,x n }  V i  {} for all 0 x ti in G i. Now join each  i with  at x ti : we can form a Eular circuit in G. QED x0x1x2 x t1 xi x tk xjx j+1 xn=x0 e1e2ei ej e j+1 11 kk

43 Discrete Mathematics Chap 9 Graphs Transparency No.9-43 Example:  = a b c d a is a simple circuit in G. removing all edges in  results in three connected components: G1,G2 and G3 intersecting with  at {a,d}, {b} and {c} respectively. By ind. hyp.,  Eular ckt :  1 = (a...a) =(aedfghefa)  2: (b) and  3: (c i j c) ==> join  and all  i, we obtain a Eular ckt of G: (aedfghefa)b(cijc)da. a b c d e f g h i j a b c d e f g h i j G1 G2 G3 G

44 Discrete Mathematics Chap 9 Graphs Transparency No.9-44 Eular condition for Eular path: Theorem 2: A connected multigraph has an Eular path which is not an Eular ckt iff it has exactly two vertices of odd degree. pf: (=>): G=(V,E): any multigraph. Let  = x0 e1 x1 e2 x2 e2 x3... en x n !=x0 be any Eular path. For each v=xi in V != x0 or xn, since ei-->xi --> e i+1 we have deg(v) = 2 |{j | xj = v and 0 Every vertex of G has even degree. By theorem 1,  a Eular circuit  = a ->.... ->b->(e)->a. ==> removing e from  we get a Eular path of G. QED

45 Discrete Mathematics Chap 9 Graphs Transparency No.9-45 Existence of simple circuit Lemma: G=(V,E): a multigraph s.t. E != {} and every vertex has even degree. Then there exist a simple ckt in G of length >0 from any vertex of nonzero degree. pf: Let x 0 be any vertex in G with nonzero degree. We construct a sequece of simple paths  ’ s which eventually becomes a simple circuit as follows: 0. Initially  1 = x 0 --e1-- x 1. G 1 = (V, E \{e1}). note: x 1 in G 1 has degree > 0 hence there is an edge leaving x assume  i = x 0...x i has been formed and G i = (V, Ei= E\{e1,...,ei}). If x i = x k for k

46 Discrete Mathematics Chap 9 Graphs Transparency No.9-46 Hamilton paths and circuits Def. 2: G=(V,E): a multi graph. A path x 0 e 1 x 1 e 2 x 2... e n x n in G is a Hamilton path if {x 0,...,x n } = V and x i  x j for all i  j. A ckt x 0 e 1 x 1 e 2 x 2... e n x n =x 0 (n > 1) in G is a Hamilton ckt if {x 1,...,x n } = V and x i  x j for all i  j Ex: Problem: Is there a simple principle, like that of Eular ckt, to determine whether a multigraph has a Hamilton ckt ? Ans: no ! In fact, there is no known polynominal time algorithm which can test if a given input multigraph has a Hamilton ckt ! Theorem: [sufficient condition] G: a connected simple graph with n  3 vertices. If every vertex has degree  n/2, then G has Hamilton ckts.

47 Discrete Mathematics Chap 9 Graphs Transparency No.9-47 Grey code Ex 8: label regions of a disc: Problem: split the disc into 2 n arcs of equal length and assign a bit string of length n to each arc s.t. adjacent arcs are assigned bit strings differing from neighbors by one bit only. Problem: How to find Gray code of n-bit length? Rule: Let Gn = (Vn,En) = Qn be the n cube. A cycle of the disc (a grey code) corresponds to an Hamilton ckt in Qn

48 Discrete Mathematics Chap 9 Graphs Transparency No Shortest path problems A weighted graph is a graph G=(V,E) together with a weighting function w:E->R +. A shortest path from a to b is a path: a e 1 x 1 e 2 x 2... e n b s.t.  i=1,n w(e i ) is minimized. Problem: Given a graph and two vertices a, z, find the length of a shortest path from a to z. Alg: [Dijkstra's algorithm] //L(v): the length of a shortest path from a to v// 1. L(a) := 0; L(v) = w(a,v) for all v ≠ a ; S := {a}; 2. While( ~S ≠ { } ){ // i.e., S ≠ V 3. u = any vertex ∉ S with minimum L(u); 4. S = S U {u}; 5. for( all v ∉ S) 6. L(v) = min(L(u) + w(u,v), L(v)) } 7. end /* L(z) = length of the shortest path from a to z}.

49 Discrete Mathematics Chap 9 Graphs Transparency No.9-49 Example: Running Time: O(n 2 ) a z b c d e a,0 z b,4 c,2 d e

50 Discrete Mathematics Chap 9 Graphs Transparency No.9-50 a,0 z b,3 c,2 d,10 e, a,0 z b,3 c,2 d,8 e,

51 Discrete Mathematics Chap 9 Graphs Transparency No.9-51 a,0 z,14 b,3 c,2 d,8 e, a,0 z,13 b,3 c,2 d,8 e,

52 Discrete Mathematics Chap 9 Graphs Transparency No.9-52 Correctness (skipped!) Let S k = the value of S after the kth iteration of the for-loop. u k = the vertex added to S k at the kth iteration. L k (v) = the value of L(v) after kth iteration. Notes S k = {u 0 =a,u 1,…,u k }. L j (u k ) = L k-1 (u k ) for all j >k L(a) := 0; L(v) = w(a,v) for all v ≠ a ; S := {a}; 2. While( ~S != { } ){ 3. u = any vertex ∉ S with minimum L(u); 4. S = S U {u}; 5. for( all v ∉ S) 6. L(v) = min(L(u) + w(u,v), L(v)) } 7. end /* L(z) = length of the shortest path from a to z}.

53 Discrete Mathematics Chap 9 Graphs Transparency No.9-53 Correctness of Dijkstra alg is a direct of the following lemma: skipped) Lemma: for all iterations k and all vertices v: 1. v  S k  L k (v) is the length of the shortest of all paths from a to v. 2. v ∉ S k  L k (v) is the length of the shortest of all paths from a to v of which all intermediate vertices must come from S k. pf: By induction on k. k = 0: Then S={a}, L k (a) = 0 is the shortest length from a to a. v ≠ a => L k (v) = w(a,v) is the length of the shortest from a to v without passing through any vertex in S. k= j+1 > 0: By step 3, L j (u k ) = min { L j (v) | v  ~S j }, and by step 4. L k (u k ) = L j (u k ). Now we show that L j (u k ) (and hence L k (u k ) ) is the shortest length of all paths from a to u k. Assume it is not. Then there must exist a shorter path  from a to u k, but such path must pass through a vertex not in S j, since by ind.hyp, L j (u k ) is the least length of all paths passing only through S j. Now let  = a --- u ----u k where u is the first vertex of  that are not in S and the subpath a --- u contains only vertices from S j. Then the length |a| = | a---u | + |u --- u k | , but |a ---u| ≥ L j (u k ) Hence it is impossible that |  | < L j (u k ). This shows (1) is true.

54 Discrete Mathematics Chap 9 Graphs Transparency No.9-54 (skipped) Now consider (2). let v be any vertex ∉ S k. The shortest path from a to v with intermediate vertices among S k either contains u k or not. 1. If it does not, then it is also a shortest path from a to v containing vertices form S j, and by ind.hyp, its length is L j (v). 2. If it conatins u k, then u k must be the last vertex before reaching v, since if a---u k,t---v is a shortest path, then the path a---t---v, where a-- -t is a shortest path from a to t, must be not longer than it. As a result, it has distance L j (u k ) + w(u k,v), where by ind.hyp., L j (u k ) is the shortest distance of all paths from a to u k passing through S j. Finally, Step 6 assigns the minimum of both cases to L k (v) and hence sastisfies lemma (2).

55 Discrete Mathematics Chap 9 Graphs Transparency No.9-55 Find the distances b/t all pairs of vertices Floyd(G:(V,E,w)) 1. for i = 1 to n for j = 1 to n d(i,j) = w(i,j); 2. for k = 1 to n ---- d(i,j) is the distance of minimum path from i to j with interior points among {1,2,...,k}. for i = 1 to n for j = 1 to n d(i,j) = min (d(i,k) + d(k,j), d(i,j)); end /* d(i,j) is the shortest distance b/t i and j */ running time : O(n 3 ). Note: we can also apply Dijkstra's alg to obtain a O(n 3 ) alg for distances of all pairs of vertices.

56 Discrete Mathematics Chap 9 Graphs Transparency No Planar graphs Def 1: A graph is planar iff it can be redrawn in the plane w/o any edges crossing. Such a drawing is called a planar representation of the graph. Ex1: K 4 : ok Ex2: Q 3 : ok Ex3: K 3,3 : not planar. Eular's formula: A planar representation splits the plane into regions (including an unbounded one. Eular showed a relation among #regions, |E| and |V|). Theorem 1: G=(V,E): a connected planar graph with e edges and v vertices. Then r (#regions) = e - v + 2. pf: By induction on G =(V,E). Let G 0,...., G n = G be a sequence of subgraphs of G.

57 Discrete Mathematics Chap 9 Graphs Transparency No.9-57 planar graphs (cont'd) G 0 contains only one vertex. G i+1 is formed from G i by adding one edge incident with one vertices in G i (and a vertex if needed) Let r i, e i, v i are #regions, #edges, #vertices in G i respectively. Basis: e 0 = 0; r 0 = 1; v 0 =1. Hence r 0 = e 0 - v Ind. step: assume r i = e i - v i + 2. Let (a i+1,b i+1 ) be the edges added to G i to form G i+1. case 1: {a i+1,b i+1 } ∈ V i : ==> a i+1 and b i+1 must be on the boundary of a common region. (o/w crossing would occur!) ==> add {a i+1,b i+1 } partition the region into 2 subregion ==> r i+1 = r i + 1; e i+1 = e i +1; v i+1 = v i. ==> r i+1 = e i+1 -v i case 2: a i+1 ∈ V n but b i+1 ∉ V i => add {a i+1,b i+1 } does not produce any region. => r i+1 = r i ; e i+1 =e i +1; v i+1 = v i +1 ==> r i+1 = e i+1 -v i QED

58 Discrete Mathematics Chap 9 Graphs Transparency No.9-58 more on planar graphs Ex4: Planar graph G has 20 vertices, each of degree 3. ==> #regions = ? r = e - v + 2 = = 12. Corollary: G: a connected planar simple graph with e edges and v vertices  3. ==> e  3v - 6. pf: for each region R: define deg(R) = #edges on the boundary of R. ==> 2e =  deg(R) [each edge shared by 2 regions] =  deg(v) Since deg(R)  3 (simple graph), 2e =  deg(R)  3 r. ==> 2e/3  r = e-v+2 ==> 3v- 6  e. QED Ex5: K 5 is not planar. sol: K5 has C(5,2) = 10 edges and 5 vertices. ==> 3v - 6 = 15-6 = 9 < 10, violating the necessary condition ! Ex6: K 3,3, though satisfying the condition: e  3v - 6, is not planar.

59 Discrete Mathematics Chap 9 Graphs Transparency No.9-59 more on planar graph: G: a connected planar simple graph of e edges and v > 2 vertices and no simple ckt of length 3 => e  2v - 4. pf: no ckt of length 3 ==> every region has degree  4. ==> 2e =  deg(R)  r. ==> e  r = 2e-2v+4 ==> e  2v - 4. Ex 6: K 3,3 is not planar. K 3,3 has 9 edges and 6 vertices and has no cycle of length 3. ==> 2 x = 8 < 9. Hence not planar. General rule about planar graphs: Def: elementary subdivision: u v ==> u------w------v.

60 Discrete Mathematics Chap 9 Graphs Transparency No.9-60 General rule about planar graphs Def: G1 and G2 are homeomorphic iff they can be obtained from the same graph by a sequence of elementary subdivisions. Ex12: Fact: G in not planar if some of its subgraphs is not planar. Theorem 2: [Kuratowski theorem] A graph is nonplanar iff its contains a subgraph which is homeomorphic to K 5 or K 3,3.

61 Discrete Mathematics Chap 9 Graphs Transparency No Graph coloring Problem: Given a map, determine at least how many colors are needed to color the map s.t. neighbor regions (with a common border) are assigned diff colors. Ex: A B C D E F G H I

62 Discrete Mathematics Chap 9 Graphs Transparency No.9-62 Transform maps into graphs Ideas: regions ---> vertices R1 and R2 share a border ---> {R1,R2} is an edges Def: M: a map G M = (V,E) where V = the set of all regions E={ {r1,r2} | r1 and r2 share a common border line in M} G M is called the dual graph of the map M. Notes: 1. Every dual graph of maps are planar graphs 2. Every planar graph is the dual graph of some map.

63 Discrete Mathematics Chap 9 Graphs Transparency No.9-63 Graph coloring Def 1:G = (V,E) : a graph. A coloring of G is the assignment of a color to each vertex s.t. no two adjacent vertices are assigned the same color. Problem: What is the least number of colors necessary to color a graph ? Def 2: G=(V,E): a graph. The chromatic number of G is the least number of colors needed for a coloring of the graph G. Problem: What is the maximum of all chromatic numbers of all planar graphs ? ==>1. a problem studied for over 100 years ! [1850~1976, solved by Appel&Haken] cases generated and verified by computer programs. 3. issue: believable ?

64 Discrete Mathematics Chap 9 Graphs Transparency No.9-64 The 4-color theorem Theorem 1: The chromatic number of a planar graph is no greater than 4. Note: 1. Theorem 1 holds for planar graphs only. 2. Non-planar graphs can have any chromatic number > 4. Ex: K 5 has chromatic number 5. In fact K n has chromatic number n for any n. Exs: #(K m,n ) = 2. #(C n ) = 2 if n is even and 3 if n is odd.

65 Discrete Mathematics Chap 9 Graphs Transparency No.9-65 Applications (scheduling and assignments) Ex 5: problem : how to assign the final exams. s.t. no student has two exams at the same time. solu: G = (V,E) where V= the set of all courses {c1,c2} in E iff  a student taking courses c1 and c2. ==> A schedule of the final examinations corresponds to a coloring of the associated graph G I II III IV I III Time courses I 1,6 ==> II 2 III 3,5 IV 4,7


Download ppt "Discrete Mathematics Transparency No. 9-1 Chapter 9 Graphs."

Similar presentations


Ads by Google