Discrete Mathematics Chapter 9 Graphs By courtesy of
Discrete Mathematics Chapter 9 Graphs By courtesy of Prof. Cheng-Chia Chen Transparency No. 9 -1
Chapter 8. Graphs Discrete Mathematics Chapter 9 Graphs l Old subject with many modern applications l Introduced by L. Euler, who used it to solve the famous Konisberg bridge problem. l 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. ) �. . Transparency No. 9 -2
Table of contents Discrete Mathematics Chapter 9 Graphs l Introduction l Graph terminology l Representing graph and graph isomorphism l Connectivity l Euler and Hamilton paths l Shortest path problems l Planer graphs l Graph coloring Transparency No. 9 -3
8. 1 Introduction Discrete Mathematics Chapter 9 Graphs l Graph: discrete structure consisting of vertices and edges that connects these vertices. l 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. �Pseudo-graph: allow self-loops and multiple edges. �Digraph (directed graph): edges are ordered pairs of vertices. �Directed multi-graph: 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). Transparency No. 9 -4
Formal definitions Discrete Mathematics Chapter 9 Graphs 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(e 1) = f(e 2) ==> e 1 and e 2 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(e 1) = f(e 2) ==> e 1 and e 2 are parallel or multiple edges. Note: f(e 1) = (u, v) / f(e 2) = (v, u) / u v => e 1 and e 2 are not parallel edges (opposite directions). Transparency No. 9 -5
Labeled (or weighted) grapghs Discrete Mathematics Chapter 9 Graphs l 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 wlabeled edge or simply a w-edge. l Hyper graph: edges can connect more than 2 vertices: �e. g hyper k-graph G = (V, E, f) where f: E-> Vk. l Summary: type directed edge? multiedge? loop? simple no no no multigraph no yes no pseudo no yes digraph yes no yes directedyes yes -multigraph Transparency No. 9 -6
Graph models Discrete Mathematics Chapter 9 Graphs Ex 1: 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. Ex 2: 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) Ex 3: Round-robin tournaments One where each team plays each other team exactly once. A B V: the set for all teams (u, v) in E iff team u beats team v. D Ex: 4 -team round-robin tournament C Transparency No. 9 -7
Graph model (cont'd) Discrete Mathematics Chapter 9 Graphs 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. Transparency No. 9 -8
Discrete Mathematics Chapter 9 Graphs Precedence graph of a program Ex 4: s 1: a : = 0; s 2: b : = 1; s 3: a : = a+1; s 4: d : = b+a; s 5: e : = d+1; s 6: e : = c+d s 1 s 2 s 3 s 4 s 5 s 6 ==> What is the precedence graph of this program? Transparency No. 9 -9
Precedence graph of a program Ex 4: s 1: a : = 0; s 2: b : = 1; s 3: a : = a+1; s 4: d : = b+a; s 5: e : = d+1; s 6: e : = c+d ==>Problems: 1. Minimum time needed to complete the program using multiple processors? (Depth) => length of longest paths + 1 2. Minimum # of processors needed to complete the program in minimum time? (Width) => p 1: [s 1, s 3, s 4, s 6], p 2: [s 2, -, -, s 5] Discrete Mathematics Chapter 9 Graphs s 1 s 2 s 3 s 4 s 5 s 6 Transparency No. 9 -10
Graph terminology Discrete Mathematics Chapter 9 Graphs Def 1: G = (V, E): undirected graph if u --e-- v ==> �u and v are adjacent (or neighbors) C B D �Edge e is incident with u (& v). �e connects u and v. G �u and v are end points of e. E F 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. Transparency No. 9 -11 A
Handshaking theorem Discrete Mathematics Chapter 9 Graphs Theorem 1: G = (V, E): an undirected graph ==> S 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: Sv in V deg(v) = Sv in V / deg(v) is odd deg(v) +Sv in V / deg(v) is even deg(v) ==> Sv in V / deg(v) is odd deg(v) is even ==> |{v in V | deg(v) is odd}| is even. QED Transparency No. 9 -12
Terminology for digraphs Discrete Mathematics Chapter 9 Graphs 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: Sv in V in-deg(v) = Sv in V out-deg(v) = |E|. Transparency No. 9 -13
Underlying undirected graph Discrete Mathematics Chapter 9 Graphs 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' have 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, 3), (2, 3), (3, 2)}) ==> G' =? Transparency No. 9 -14
Special simple graphs Discrete Mathematics Chapter 9 Graphs Ex 4: complete graphs Kn = (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: Cn (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) Wn = (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 =? Ex 7: n-cubes Qn = (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: 11011 and 11111 is connected. Ex: Q 1, Q 2, Q 3, Q 4 =? Transparency No. 9 -15
Discrete Mathematics Chapter 9 Graphs 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 V 1 and the other end point is in V 2. a b Ex 8: Is C 6 bipartite? (yes! why? ) g Ex 9: Is K 3 bipartite? (no! why? ) f c Ex 10: Which of Fig G and H is bipartite? d e G Ex 11: Km, n (complete bipartite graph) Km, n = ({u 1, . . . , um} U {v 1, . . . , vn}, E} , where E = {{ui, vj} | i=1. . m v = 1. . n} eg: K 2, 3, K 3, 3 = ? a b f e H d c Problem: Km, n has ? edges Transparency No. 9 -16
Ex 13: interconnection network for processors Discrete Mathematics Chapter 9 Graphs Types of connections �Linear array �Mesh �Hyper cube (m-cube) Main measures: linear array mesh m-cube (n=2 m) 1. #links n-1 2 sqrt(n)(sqrt(n)-1) nm/2 = O(n lg n) 2. longest distance n-1 2(sqrt(n) -1) m = lg n Transparency No. 9 -17
New graphs from old Discrete Mathematics Chapter 9 Graphs 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] G 1 = (V 1, E 1); G 2 = (V 2, E 2): two graphs ==> G 1 U G 2 =def (V 1 U V 2, E 1 U E 2) Note: Not only V 1 and V 2, but also E 1 and E 2 may overlap. Ex: G 1 = ({a, b, c, d, e}, {ab, bc, ce, be, ad, de}) G 2 = ({a, b, c, d, f}, {ab, bc, bd, bf}} ==> G 1 U G 2 =? Def 7': Disjoint union of graphs: (skip) Disjoin union of G 1 and G 2 =? Transparency No. 9 -18
Graph representation and graph isomorphism Discrete Mathematics Chapter 9 Graphs l 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|). l adjacent list: for each vertex v, a[v] is the list of all adjacent vertices of v. l adjacent matrix: M[u, v]=1 iff {u, v} (or (u, v) if directed) is an edge. l incident matrix: I[u, e] = 1 iff u in f(e), or (for directed graph) i[u, e]= 1 (or -1) iff u is the starting (or ending) vertex of e. Ex: (p 558 fig 2) Transparency No. 9 -19
Graph isomorphism Discrete Mathematics Chapter 9 Graphs Def. 1: G 1 = (V 1, E 1), G 2 = (V 1, E 2): two simple or digraphs �G 1 and G 2 are isomorphic iff $ a bijection h: V 1 ->V 2 s. t. for all u, v in V 1, {u, v} (or (u, v)) E 1 iff {h(u), h(v)} (or (h(u), h(v))) E 2. �Such h is called an isomorphism (b/t G 1 and G 2). Ex 8: Are G = ({1234}, {12, 23, 34, 41}) and H = ({abcd}, {ad, ac, bd}) isomorphic? Fact: If G 1 and G 2 are isomorphic ==> |V 1| = |V 2| & |E 1| = |E 2|, and G 1 and G 2 have the same degree type. Def: For each G = (V, E), type(G) is the multiset {deg(v) | v V}. Transparency No. 9 -20
Connectivity Discrete Mathematics Chapter 9 Graphs Def 1: G = (V, E, f): an undirected [multi-]graph �A path a of length n > 0 from u to v is a sequence of edges e 1, e 2, . . . , en s. t. f(e 1) = {u, x 1}, f(e 2) = {x 1, x 2}, …, f(en) = {xn-1, v}. e 1 e 2 e 3 e 4 e 5 e 6 en-1 en u=x 0 ----x 1 -----x 2 ----x 3 ----x 4 ----x 5 ---- …. ----xn-1 ----Xn=v �If G is a simple graph ==> a can be identified by the sequence of vertices: x 0 = u, x 1, . . . , xn-1, xn = v. �a is a circuit (or cycle) iff x 0 = xn. �a is simple if all edges in the path are distinct (i. e. , for all 0≤ i<j≤ n, ei ej ). Transparency No. 9 -21
Connectivity (cont'd) Discrete Mathematics Chapter 9 Graphs Def. 2: G = (V, E, f): a directed multigraph �A path a of length n > 0 from u to v is a sequence of edges e 1, e 2, . . . , en s. t. f(e 1) = (u, x 1), f(e 2) = (x 1, x 2), . . . f(en) = (xn-1, v). �If G is a digraph ==> a can be identified by the sequence of vertices: x 0=u, x 1, . . . , xn-1, xn = v. �a is a circuit (or cycle) iff x 0 = xn. �a is simple if all edges in the path are distinct (i. e. , for all 0<i<j<n+1, ei ej ). Def 3: An undirected graph is connected if there is a path between every pair of distinct vertices. Transparency No. 9 -22
Discrete Mathematics Chapter 9 Graphs 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 a = e 1, e 2, . . . , en be any path of least length from u to v. Then a must be a simple path. If it were not, then there would be 0£ i <j £n s. t. ei = ej. ==> the path b = e 1, . . , ei-1, ej+1, . . , en or e 1, . . , ei, ej+1, . . , en is another path from u to v with length < |a|, a contradiction!. QED join xi-1 and xj if x i-1 = xj e 1 u e 2 x 1 . . . x 2 ei xi-1 xi . . . . ej+1 ej xj-1 join xi and xj if xi = xj xj . . . xj+1 v Transparency No. 9 -23
Discrete Mathematics Chapter 9 Graphs xj xi ei e 1 e 2 u x 1 x 2 xj+1 ej . . . v xj-1 xi ei e 1 e 2 . . . x 2 . . . xi-1 xj-1 u x 1 ej+1 xi-1 xj ej xj+1 . . . v ej+1 Note: Theorem 1 does not hold for circuit (cycle) Transparency No. 9 -24
A theorem about simple circuits Discrete Mathematics Chapter 9 Graphs l G = (V, E): an 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. (skip) Pf: Let a 1: x 0 --(e 1)-- x 1 --(e 2)-- x 2 --(e 3)--…--(et)--xt--(et+1)--xt+1 --…---xn=v, and a 2: x 0 --(e 1)-- x 1 --(e 2)-- x 2 --(e 3)--…--(et)--xt--(e’t+1)--yt+1 --…---ym=v, be two distinct simple paths fro u to v in G If either a 1 or a 2 contains a (simple) circuit, then we are done. Otherwise let et+1, e’t+1 the first edges with et+1 ≠ e’t+1. let J be the least number in {t+1, …, m} such that y. J = xs where s is any vertex occurring in path a 1 (i. e. , y. J=xs ∈ {x 0, …, xn}). Note since ym = xn= v, such J must exist. Transparency No. 9 -25
A theorem about simple circuits Discrete Mathematics Chapter 9 Graphs Now it is easy to see that: 1. If s ≤ t then { xs --(es+1)-- xs+1 --…--(et)—xt } U { xt--(e’t+1)--yt+1 --…--(e’J-1)-y. J } is a circuit. This is not possible since all edges of the circuit are part of a 2. 2. If s > t then {xt--(et+1)--xt+1 --…-(es-1)--xs} U { xt--(e’t+1)--yt+1 --…--(e’J-1)-y. J } ---(*) is a simple circuit. Note: {xt, xt+1, …, xs} ⋂ {xt, yt+1, …, y. J } = {xt, y. J=xs} If there were ea = e’b => f(ea) = {xt, xt+1=xs} = {xt, yt+1=y. J} => a=b=t+1 => e t+1 = e’t+1 a contradiction! o/w, by def, (*) is a simple circuit. Transparency No. 9 -26
Discrete Mathematics Chapter 9 Graphs Xt xs u y. J et+1 e’t+1 v es xs e’J y. J-1 Transparency No. 9 -27
Connected components Discrete Mathematics Chapter 9 Graphs l G = (V, E): an 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 covering G'. ) Ex: Transparency No. 9 -28
Connected components (cont'd) Discrete Mathematics Chapter 9 Graphs Note 1. Every two distinct connected components are disjoint. Pf: G 1 = (V 1, E 1), G 2 = (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 U E 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. (skip) Transparency No. 9 -29
Connected components (cont'd) Discrete Mathematics Chapter 9 Graphs Pf: Let i = 0 and Gi = G'. If Gi is maximal then we are done. o/w, there is connected Gi+1 contains Gi. If Gi+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, . . . , Gk be the set of all connected components of G. Then G = Ui = 1. . k Gi Pf: 1. Ui=1, k Gi Í G since every Gi Í G. 2. G Í Ui=1, k. Gi since every edge and every vertex must belong to some connected component. Transparency No. 9 -30
Connected components (cont'd) Discrete Mathematics Chapter 9 Graphs Note 4: Every undirected graph G has a unique set of connected components. (skip) Pf: Let G = (V, E). For each vertex u in V, let Gu = (Vu, Eu) where Vu = {v | there is a path from u to v} Í V, and Eu = {e | f(e) Í Vu} Í E. It is easy to show that Gu is a connected component of G. Moreover, we have 1. for all u, v ∈ V: Gu = Gv iff Vu=Vv / Eu=Ev and 2. for all e ∈ E: if f(e) = {u, v} ==> Gu=Gv and e Eu. Hence the set of connected components of G = {Gu | u V}. Note: Connected components in graphs play a role like equivalence classes in equivalence relations. Transparency No. 9 -31
The connectivity relation in a graph (skip) Discrete Mathematics Chapter 9 Graphs l 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. l 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, Gu = (Vu, Eu) = ([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/~}. Transparency No. 9 -32
Cut vertices and cut edges Discrete Mathematics Chapter 9 Graphs l 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. l Cut edges (bridges) The removal of it will result in graph with more connected components. a d f g Ex 4: Determine all cut vertices and all bridges in the right graph. b cut vertices =? h c e bridges =? Transparency No. 9 -33
Discrete Mathematics Chapter 9 Graphs 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 the underlying graph of G. Ex 5: G H G is strongly connected. H is weakly connected. Transparency No. 9 -34
Path and isomorphism Discrete Mathematics Chapter 9 Graphs l 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). Ex 1: Pm, 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. Transparency No. 9 -35
Discrete Mathematics Chapter 9 Graphs More on graph isomorphism Ex 2: P 2(G) = "G has a simple circuit of length k", where k is a number > 2, is an isomorphic invariant. Pf: G 1 = (V 1, E 1), G 2 = (V 2, E 2): two simple graphs. Let h: V 1 ->V 2 be any isomorphism from G 1 to G 2. Then if x 0 --(e 1)--> x 2 --(e 2)--> x 3 --. . -->(en)-->xn is a simple path on G 1, then the sequence h(x 0) -->(h(e 1))-->h(x 2)--(h(e 2))-->h(x 3)--. . . -->((h(en))-->h(xn) is also a simple path on G 2. 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 3. 3 2 2 3 1 4 6 G 5 1 4 6 H 5 Transparency No. 9 -36
Counting paths b/t vertices Discrete Mathematics Chapter 9 Graphs G = (V, E) with V = {V 1, . . . , Vn} : a simple graph with adjacent matrix M. ==> # different paths of length k from vi to vj = (Mk)ij, where scalar multiplication are integer product (instead of boolean AND). Pf: by math ind on k. 1. basis step: k = 1: => By def. Mij is the number of edges (= path of length 1) from vi to vj. 2. Ind. step: assume (Mm)ij = #paths of length m from vi to vj for all m < k and for all ui, uj ∈ V. But #paths of length k from vi to vj = #paths of length k-1 from ui to v 1 x #paths of length 1 from v 1 to vj + #paths of length k-1 from ui to v 2 x #paths of length 1 from v 2 to vj +. . . + #paths of length k-1 from ui to vn x #paths of length 1 from vn to vj = St=1. . n (Mk-1)it x Mtj = (MK)ij. Transparency No. 9 -37
Example Discrete Mathematics Chapter 9 Graphs Ex 8: G = ({1, 2, 3, 4}, {12, 13, 24, 34}) ==> M = [0110; 1001; 0110] ==> M 4 = [8008; 0880; 8008] ==> There are 8 different paths of length 4 from a to d. Notes: 1. The length of the shortest path from vi to vj is the least k s. t. (MK)ij != 0. 2. G is connected if (Sk=1. . n-1 Mk )ij != 0 for all 1≤ i<j ≤ n. Pf: G is connected => for any i ≠ j, there is a simple path (of length t < n) from v i to vj ==> (Mt)ij > 0 ==> (Sk=1. . n-1 Mk )ij != 0. QED Transparency No. 9 -38
Discrete Mathematics Chapter 9 Graphs Euler and Hamilton paths C l The seven bridges problem: A l 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? D B The town of Konigsburg C D A B Transparency No. 9 -39
Discrete Mathematics Chapter 9 Graphs Eular paths and Eular cycles Def. 1: A Eular path in a multigraph G is a simple path containing all edges. Def. 2: A Eular circuit in a multigraph G is a simple circuit containing all edges. Ex 1: In G 1, G 2 and G 3: G 1 has a Eular a b a b circuit: a, e, c, d, e, b, a. e G 3 has a Eular path: d bedbadca. e G 1 c d G 2 c c G 3 d e 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. Transparency No. 9 -40
Discrete Mathematics Chapter 9 Graphs Necessary and sufficient conditions for Eular paths and Eular circuits Theorem 1: A connected multigraph has a 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 a = x 0 e 1 x 1 e 2 x 2 e 2 x 3. . . en xn=x 0 be any Eular circuit. For each v=xi in V ≠ x 0, since ei-->xi --> ei+1 we have deg(v) = 2 |{j | xj = v and 0<j<n}| and for x 0 we have deg(x 0) = 2 x|{j | xj = x 0 and 0<j<n }| + 2. Hence every vertex has even degree. (<=): by induction on |E|. If |E|=0, by definition, it has a Eular ckt. O/W Let a = x 0 e 1 x 1 e 2 x 2 e 3. . . en xn=x 0 be any simple circuit. (its existence will be shown later. ) If a is a Eular circuit, then we are done. O/W: Transparency No. 9 -41
Discrete Mathematics Chapter 9 Graphs Proof of Eular condition Let G' = (V', E') be the resulting graph formed from G by removing all e 1, e 2, . . . , en from E. Let G 1 = (V 1, E 1), . . . , Gk =( Vk, Ek) be all connected components of G'. Since G is connected, {x 0, . . . , xn} ÇVi != {} for all 0<i<k+1. (o/w there is no path from x 0 to vertices in Vi). For each i let xti be any vertex in {x 0, . . . , xn} Ç Vi. Since Gi = (Vi, Ei) and |Ei| < |E| and every vertex in Vi has even degree, by ind. hyp. there is a Eular circuit ai = xti ->. . . -> xti in Gi. Now join each ai with a at xti: a 1 e 1 x 0 e 2 x 1 . . . x 2 ak ei xt 1 xi ej+1 ej . . . . xtk xj . . . xj+1 xn=x 0 we can form a Eular circuit in G. QED. Transparency No. 9 -42
Discrete Mathematics Chapter 9 Graphs Example: (skip) h g l a = a b c d a is a simple circuit in G. f e l removing all edges in a results in a three connected components: d G 1, G 2 and G 3 intersecting with G a at {a, d}, {b} and {c} respectively. b By ind. hyp. , c $ Eular ckt : a 1 = (a. . . a) g h =(aedfghefa) f e a 2: (b) and a d G 1 a 3: (c i j c) ==> join a and all ai, we obtain i G 3 a Eular ckt of G: b G 2 j (aedfghefa)b(cijc)da. c Transparency No. 9 -43 i j
Eular condition for Eular paths: Discrete Mathematics Chapter 9 Graphs Theorem 2: A connected multigraph has an Eular path but not a Eular ckt iff it has exactly two vertices of odd degree. Pf: (=>): G = (V, E): any multigraph. Let a = x 0 e 1 x 1 e 2 x 2 e 2 x 3. . . en xn != x 0 be any Eular path. For each v=xi in V != x 0 or xn, since ei-->xi --> ei+1 we have deg(v) = 2 |{j | xj = v and 0<j<n}| and for v = x 0 or xn we have deg(v) = 2 x|{j | xj = v and 0<j<n } + 1. Hence all vertices but x 0 and xn have even degree. (<=): Let G' = (V, EU{e}) where e is a new edge connecting a and b, which are vertices of G with odd degree. ==> Every vertex of G has even degree. By theorem 1, $ a Eular path a = a ->. . ->b->(e)->a. ==> removing e from a we get a Eular path of G. QED Transparency No. 9 -44
Existence of simple circuits Discrete Mathematics Chapter 9 Graphs Lemma: G = (V, E): a multigraph s. t. E != {} and every vertex has even degree. Then there exist a simple ckt in G 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 a’s which eventually become a simple circuit as follows: 0. Initially a 1 = x 0 --e 1 -- x 1. G 1 = (V, E {e 1}). note: x 1 in G 1 has degree > 0 hence there is an edge leaving x 1. assume ai = x 0. . . xi has been formed and Gi = (V, Ei= E{e 1, . . . , ei}). If xi = xk for k<i then xk-ek- - … xi is a simple ckt and we are done. o/w by ind. hyp. xi has odd degree in Gi, hence we can find an edge e in Gi connecting xi and some other vertex u. now let ai+1= ai -- e--u; xi+1 = u ; and i = i+1 2. goto 1. Note: the procedure must terminate since every iteration of step 1 will result in one edge removed from G, but G has only a finite number of edges. So the prod. will exit from step 1 with a simple ckt returned. QED Transparency No. 9 -45
Hamilton paths and circuits Discrete Mathematics Chapter 9 Graphs Def. 2: G = (V, E): a multigraph. l A path x 0 e 1 x 1 e 2 x 2. . . en xn in G is a Hamilton path if {x 0, . . . , xn} = V and xi xj for all i j. l A ckt x 0 e 1 x 1 e 2 x 2. . . en xn=x 0 (n > 1) in G is a Hamilton ckt if {x 1, . . . , xn} = V and xi xj 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. Transparency No. 9 -46
Discrete Mathematics Chapter 9 Graphs Grey code (skip) 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: 111 000 How to find Gray code 100 001 110 of n-bit length? 001 101 010 Rule: Let Gn = (Vn, En) 101 100 011 111 = Qn be the n cube. 110 010 111 011 A cycle of the disc 101 (a grey code) corresponds 001 to an Hamilton ckt in Qn. 010 000 110 100 Transparency No. 9 -47
Shortest path problems Discrete Mathematics Chapter 9 Graphs l A weighted graph is a graph G = (V, E) together with a weighting function w: E->R+. l A shortest path from a to b is a path: l a e 1 x 1 e 2 x 2. . . en b s. t. Si=1, n w(ei) is minimized. l Problem: Given a graph and two vertices a, z, find the length of a shortest path from a to z. l 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}. Transparency No. 9 -48
Discrete Mathematics Chapter 9 Graphs Example: l Running Time: O(n 2) b d 5 6 4 8 1 a z 2 3 2 10 c b, 4 e d 5 6 4 1 a, 0 8 z 2 3 2 c, 2 10 e Transparency No. 9 -49
Discrete Mathematics Chapter 9 Graphs b, 3 d, 10 5 6 4 8 1 a, 0 z 2 3 2 c, 2 b, 3 10 e, 12 5 d, 8 6 4 1 a, 0 8 z 2 3 2 c, 2 10 e, 12 Transparency No. 9 -50
Discrete Mathematics Chapter 9 Graphs b, 3 d, 8 5 6 4 8 1 a, 0 z, 14 2 3 2 c, 2 b, 3 10 e, 10 5 d, 8 6 4 1 a, 0 8 z, 13 2 c, 2 10 e, 10 Transparency No. 9 -51
Correctness (skipped!) Discrete Mathematics Chapter 9 Graphs l Let Sk = the value of S after the kth iteration of the for-loop. �uk = the vertex added to Sk at the kth iteration. �Lk(v) = the value of L(v) after kth iteration. l Notes �Sk = {u 0=a, u 1, …, uk}. �Lj(uk) = Lk-1(uk) for all j >k-1. 1. 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}. Transparency No. 9 -52
Discrete Mathematics Chapter 9 Graphs Correctness of Dijkstra alg is a direct app. of the following lemma: (skipped) l Lemma: for all iterations k and all vertices v: � 1. v Sk Lk(v) is the length of the shortest of all paths from a to v. � 2. v ∉ Sk Lk(v) is the length of the shortest of all paths from a to v of which all intermediate vertices must come from Sk. pf: By induction on k. k = 0: Then S={a} , Lk (a) = 0 is the shortest length from a to a. v ≠ a => Lk (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, Lj(uk ) = min { Lj(v) | v ~Sj }, and by step 4. Lk(uk) = Lj(uk). Now we show that Lj(uk) (and hence Lk(uk) ) is the shortest length of all paths from a to uk. Assume it is not. Then there must exist a shorter path a from a to uk, but such path must pass through a vertex not in Sj, since by ind. hyp, Lj(uk) is the least length of all paths passing only through Sj. Now let a = a --- u ----uk where u is the first vertex of a that are not in S and the subpath a --- u contains only vertices from Sj. Then the length |a| = | a---u | + |u --- uk|, but |a ---u| ≥ Lj(uk) Hence it is impossible that |a| < Lj(uk). This shows (1) is true. Transparency No. 9 -53
(skipped) Discrete Mathematics Chapter 9 Graphs Now consider (2). let v be any vertex ∉ Sk. The shortest path from a to v with intermediate vertices among Sk either contains uk or not. 1. If it does not, then it is also a shortest path from a to v containing vertices form Sj, and by ind. hyp, its length is Lj(v). 2. If it conatins uk, then uk must be the last vertex before reaching v, since if a---uk, 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 Lj(uk) + w(uk, v), where by ind. hyp. , Lj(uk) is the shortest distance of all paths from a to uk passing through Sj. Finally, Step 6 assigns the minimum of both cases to L k(v) and hence sastisfies lemma (2). Transparency No. 9 -54
Find the distances b/t all pairs of vertices Discrete Mathematics Chapter 9 Graphs l 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. Transparency No. 9 -55
Planar graphs Discrete Mathematics Chapter 9 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. Ex 1: K 4: ok Ex 2: Q 3: ok Ex 3: 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, . . , Gn = G be a sequence of subgraphs of G. Transparency No. 9 -56
Planar graphs (cont'd) Discrete Mathematics Chapter 9 Graphs G 0 contains only one vertex. Gi+1 is formed from Gi by adding one edge incident with one vertices in Gi (and a vertex if needed) Let ri, ei, vi are #regions, #edges, #vertices in Gi respectively. Basis: e 0 = 0; r 0 = 1; v 0 =1. Hence r 0 = e 0 - v 0 + 2. Ind. step: assume ri = ei - vi + 2. Let (ai+1, bi+1) be the edges added to Gi to form Gi+1. case 1: {ai+1, bi+1 } ∈ Vi: ==> ai+1 and bi+1 must be on the boundary of a common region. (o/w crossing would occur!) ==> add {ai+1, bi+1} partition the region into 2 subregion ==> ri+1 = ri + 1; ei+1 = ei +1; vi+1 = vi. ==> ri+1 = ei+1 -vi+1+2. case 2: a i+1 ∈ Vn but b i+1 ∉ Vi => add {ai+1, bi+1 } does not produce any region. => ri+1 = ri; ei+1=ei+1; vi+1 ==> ri+1 = ei+1 -vi+1+ 2. QED Transparency No. 9 -57
More on planar graphs Discrete Mathematics Chapter 9 Graphs Ex 4: G has 20 vertices, each of degree 3. ==> #regions = ? r = e - v + 2 = 30 - 20 + 2 = 12. Corollary: G: a connected planar simple graph with e edges and v vertices ³ 3. ==> e £ 3 v - 6. pf: for each region R: define deg(R) = #edges on the boundary of R. ==> 2 e = S deg(R) [each edge shared by 2 regions] =S deg(v) Since deg(R) ³ 3 (simple graph), 2 e = S deg(R) ³ 3 r. ==> 2 e/3 ³ r = e-v+2 ==> 3 v- 6 ³ e. QED Ex 5: K 5 is not planar. sol: K 5 has C(5, 2) = 10 edges and 5 vertices. ==> 3 v - 6 = 15 -6 = 9 < 10, violating the necessary condition ! Ex 6: K 3, 3, though satisfying the condition: e £ 3 v - 6, is not planar. Transparency No. 9 -58
Discrete Mathematics Chapter 9 Graphs More on planar graph: l G: a connected planar simple graph of e edges and v > 2 vertices and no simple ckt of length 3 => e £ 2 v - 4. pf: no ckt of length 3 ==> every region has degree ³ 4. ==> 2 e = S deg(R) ³ 4 r. ==> e ³ 2 r = 2 e-2 v+4 ==> e £ 2 v - 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 6 - 4 = 8 < 9. Hence not planar. General rule about planar graphs: Def: elementary subdivision: u-------v ==> u------w------v. Transparency No. 9 -59
General rule about planar graphs Discrete Mathematics Chapter 9 Graphs Def: G 1 and G 2 are homeomorphic iff they can be obtained from the same graph by a sequence of elementary subdivisions. Ex 12: 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. Transparency No. 9 -60
Discrete Mathematics Chapter 9 Graphs Graph coloring l 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. l Ex: H B C I G A D E F Transparency No. 9 -61
Transform maps into graphs Discrete Mathematics Chapter 9 Graphs l Ideas: �regions ---> vertices �R 1 and R 2 share a border ---> {R 1, R 2} is an edges l Def: M: a map GM = (V, E) where �V = the set of all regions �E={ {r 1, r 2} | r 1 and r 2 share a common border line in M} �GM 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. Transparency No. 9 -62
Graph coloring Discrete Mathematics Chapter 9 Graphs 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] 2. 2000 cases generated and verified by computer programs. 3. issue: believable ? Transparency No. 9 -63
Discrete Mathematics Chapter 9 Graphs 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 Kn has chromatic number n for any n. Exs: #(Km , n) = 2. #(Cn) = 2 if n is even and 3 if n is odd. Transparency No. 9 -64
Discrete Mathematics Chapter 9 Graphs Applications (scheduling and assignments) Ex 5: Problem: how to assign the final exams s. t. no student has two exams at the same time. Sol: G = (V, E) where � V = the set of all courses � {c 1, c 2} in E iff $ a student taking courses c 1 and c 2. ==> A schedule of the final examinations corresponds to a coloring of the associated graph G. IV 7 1 I 2 II 3 I 6 III 5 III Time I ==> II IV courses 1, 6 2 3, 5 4, 7 4 IV Transparency No. 9 -65
- Slides: 65