WUCT121 Discrete Mathematics Graphs WUCT121 Graphs 1
Section 1. Graphs 1.1. Introduction Graphs are used in many fields that require analysis of routes between locations. These areas include communications, computer networks and transportation. Diagrammatically a graph is drawn as points representing locations and lines or curves which represent connections between locations. The points are known as vertices and the lines are called edges. WUCT121 Graphs 2
Example: v 2 e 1 e 7 e 8 e 2 e 3 e 6 e 4 e 5 v 5 v 3 v 4 e 9 Each of the v i are vertices and the e i are the edges. In this example, the single point is called a vertex. ( 1 v 2 v, ) is an edge and is written as e = v, ) 1 ( 1 v2 Further we say e 1 is incident on and v 2, and also that and v 2 are incident on e 1. and v 2 are incident on the same edge e 1 so and v 2 are said to be adjacent vertices. Similarly, e 1 and e 2 are each incident on v 2, and so e 1 and e 2 are said to be adjacent edges. WUCT121 Graphs 3
1.2. Definitions: 1.2.1. Graph. A graph G consists of a pair of non-empty finite sets V and E. V is the set of vertices and E is the set of edges of G. The elements of E are pairs of elements of V. Thus to determine a graph a set of vertices and a set of edges is required. To determine a set of edges a set of pairs of vertices is required 1.2.2. Parallel Edges. If two distinct edges have the same pair of endpoints, then the edges are said to be parallel. Example: In the previous graph, e 2 and e 8 are parallel edges 1.2.3. Loops. An edge which is defined by a single vertex is called a loop. A vertex which is the endpoint of a loop is said to be adjacent to itself. e 1 WUCT121 Graphs 4
Exercises: Draw a graph which has 4 vertices, 1 loop and one pair of parallel edges. Write down one pair of adjacent vertices and one pair of adjacent edges. e 1 e 2 v 2 e 3 e 4 V = v, v, v, }. { 1 2 3 v4 Loop: e = v, ) 1 ( 1 v1 Parallel Edges: e 3 and e 4. and v 2 are adjacent vertices. e 1 and e 2 are adjacent edges v 3 4 e 5 v WUCT121 Graphs 5
Write down the set V of vertices and the set E of edges for the following graph, G 1. v 3 v 4 e 5 e 6 e 3 e 4 e 1 e 2 v 2 { v, v, v v } V = 1 2 3, 4, E = { e, e, e, e, e, e } 1 = {( v 1 2, v 1 3 4 ), ( v 1, v 5 4 6 ), ( v 2, v 4 ), ( v 2, v 4 ), ( v 1, v 2 ), ( v 3, v 4 )} WUCT121 Graphs 6
Is the following graph G 2 the same as the previous graph G 1? e 1 e 5 v 4 e 2 e 3 e 4 v 3 e 6 v 2 Yes Notes: There is no vertex of intersection. In the previous graph G 1, where the edges e 5 and e 6 cross is not a vertex. vertex. The vertices determine the edges. Parallel loops are loops incident on the same vertex. A vertex without any edges is called an isolated A graph need not be connected, that is, it need not be in one piece. WUCT121 Graphs 7
Exercises: Draw a graph which has 6 vertices, 1 pair of parallel loops, 1 pair of parallel edges, one isolated vertex and which is made up of 3 pieces or components. e 1 e 2 e 5 v 3 v 2 v 6 e 3 e 4 v 5 e 6 v 4 WUCT121 Graphs 8
1.2.4. Degree. The degree of a vertex v, written δ (v), is the number of edges incident on v. Notes: δ ( v) = If v is a vertex with a single loop as its edge, then 2. The reason for this convention is that each edge other than a loop is incident on 2 vertices. So, for consistency, the single vertex of a loop should be thought as both starting and ending point for the loop. Each loop incident on vertex v will contribute 2 to the value of δ (v). Example: What is the degree of in the following graph? e 1 e 2 v 2 e 3 v 3 δ ( ) = 4 WUCT121 Graphs 9
Exercises: Write down the degree of each of the vertices in the following graphs: v 4 e 5 e 6 e 3 e 4 e 1 v 3 e 2 v 2 δ ( v ) =, δ ( v ) = 4, δ ( v ) = 4, δ ( v ) 3 1 1 2 3 4 = e 1 e 2 e 3 v 2 v 4 e5 e 4 δ δ ( v1 ) = 5, δ ( v2 ) = 3, δ ( v3 ) = 2, δ ( v4 ) ( v ) = 1, δ ( v ) = 1 5 v 5 6 e 6 v 6 v 3 = 0, WUCT121 Graphs 10
For each of the above graphs calculate δ ( ) k i= 1 k = 4 in the first graph and k = 6 in the second k 4 i i = 1 i = 1 The first graph, ( v ) = δ ( v ) = 12 δ. k 6 i i = 1 i = 1 The second graph, δ ( v ) = δ ( v ) = 12 i i v i, where Note: The first graph was a connected graph and 4 i= 1 ( ) = 2 6 = 12 = 2 number of edges δ. v i The second graph is disconnected and 6 i = 1 ( ) = 2 6 = 12 = 2 number of edges δ. v i Is this formula always true? WUCT121 Graphs 11
1.3. Euler s Laws 1.3.1. Euler s First Law In any graph, the sum of the degrees of the vertices equals twice the number of edges. Proof: Each edge of a graph, including loops by convention, has two ends. Thus each edge contributes 2 to the sum of the degrees of the vertices, by adding 1 to each of its endpoints. Thus the sum of the degrees of the vertices equals twice the number of edges. The number ( v) G. δ is sometimes called the total degree of v V Euler's First Law could be summarised ( v) = m( E) 2 δ, v V where m ( E) is the number of edges of the graph. Exercises: Draw a graph with 4 vertices having degrees 1, 2, 0 and 2. 4 Since ( ) = 5 i = 1 v i δ (an odd number), this is not possible WUCT121 Graphs 12
1.3.2. Euler s Second Law In any graph, the number of vertices which have odd degree is even Exercises: Draw some different graphs each with 3 vertices having degrees 1, 2 and 3. e 1 v 2 e 2 e 3 v 3 e 1 v 2 e 2 e 3 v 3 Are these graphs the same? No WUCT121 Graphs 13
1.4. Simple Graphs and Sub-Graphs Knowing the number of vertices in a graph and the degree of each vertex is not enough information to draw the graph in a unique way. 1.4.1. Simple Graph A graph which has neither loops nor parallel edges is called a simple graph. Example: e 1 v 2 e 2 v 4 Exercises: e 3 v 3 Draw a simple graph with 3 vertices having degrees 1, 2 and 3. Not possible WUCT121 Graphs 14
1.4.2. Sub-Graph Let G = V G, E } be a graph. { G H = V H, E } is said to be a sub-graph of G if { H 1. VH VG and 2. EH EG That is, H is a sub-graph of G if each of the vertices of H is a vertex of G, and each of the edges of H is an edge of G. Every graph G is a sub-graph of G. 1.4.3. Proper Sub-Graph Let G = V G, E } be a graph. { G H = V H, E } is said to be a proper sub-graph of G if { H 1. VH VG and 2. EH EG and 3. H G WUCT121 Graphs 15
Exercises: Let G be given by e 1 e 5 v 4 e 2 e 3 e 4 v 3 e 6 v 2 Draw the sub-graph H = {{ v1, v2, v3, v4}, { e3, e5, e6}} e 5 v 4 e 3 v 3 e 6 WUCT121 Graphs 16
1.5. Paths Let G = { V, E} be a graph and let u, v V. A path from u to v is an alternating sequence of vertices and edges of the form: u,, 1 1 2 2 α n eα, vβ, eα, vβ, K, e v. Example: Consider the graph e 1 e 5 v 4 e 2 e 3 e 4 v 3 e 6 v 2 Suppose we want to walk from (the bar) to v 3 (67.107). How could we proceed? One possible path is, e2, v2, e6, v3. But, after an extra long lunch, one might take the following path, e1, v1, e5, v4, e3, v2, e4, v4, e3, v2, e6, v3. WUCT121 Graphs 17
1.5.1. Length of a Path Let G = { V, E} be a graph and let u, v V. A path of length n from u to v is an alternating sequence of vertices and edges of the form u, e, vβ, e, v, 1 α 2 β 2, e, 1 α n α K If we let u = v β0 and n v v = v then each edge defined by: e = ( v, v ), for i = 1Kn Example: α i β β β i 1 i e α is i The path, e2, v2, e6, v3 from the previous has length 2 The path, e1, v1, e5, v4, e3, v2, e4, v4, e3, v2, e6, v3 from the previous has length 6 1.5.2. Open Path A path is open if finishes at different vertices. Example: u v. That is if the path begins and The path, e2, v2, e6, v3 is open since u = v v3 = v 1. The path, e1, v1, e5, v4, e3, v2, e4, v4, e3, v2, e6, v3 is open since u = v1 v3 = v. WUCT121 Graphs 18
1.5.3. Closed Path A path is closed if finishes at the same vertex. Example: u = v. That is if the path begins and The path, e2, v2, e3, v4, e5, v1 is closed since u = = v. 1.5.4. Simple Path Let G = { V, E} be a graph and let u, v V. A simple path from u to v is a path which does not contain a repeated edge nor a repeated vertex. Examples: The path, e2, v2, e6, v3 is simple since no vertices or edges are repeated. The path, e1, v1, e5, v4, e3, v2, e4, v4, e3, v2, e6, v3 is not simple since e 3 is repeated. WUCT121 Graphs 19
Exercises: Consider the graph e 1 e 5 v 4 e 2 e 3 e 4 v 3 e 6 v 2 Write down a simple path from: o to v 3 v 1 e2, v2, e6,, v 3 o v 4 to v, v 4 e5, 1 o v 4 to v 2 v, v 4 e3, 2 WUCT121 Graphs 20
1.6. Connected Graphs 1.6.1. Definition Let G = { V, E} be a graph. A pair of vertices u, v V are said to be connected if there exists a path from u to v. The graph G is said to be connected if and only if u, v V, there exists a path from u to v. 1.6.2. Connected Component Let G = { V, E} be a graph. A sub-graph H of G is said to be a connected component of G if 1. H is connected, and 2. there is no connected sub-graph of G which has H as a proper sub-graph. Notes: A graph is connected if and only if it has only one connected component Every graph is the union of its connected components. WUCT121 Graphs 21
Exercises: Consider the graph G. e 1 e 2 e 3 v 2 v 4 e5 e 4 v 5 e 6 v 6 v 3 Which of the following graphs are connected components of G? H 1 = {{ v4, v5, v6}, { e6}} No, there is no path from v 4 to v 5 H = {{ 4 }, { }} Yes 2 v H 3 = {{ v1, v2, v3}, { e3, e5}} No, H 3 is a proper sub-graph of H = {{ v1, v2, v3}, { e1, e2, e3, e4, e5}}, which is a connected sub-graph of G. WUCT121 Graphs 22
Exercises: Draw a connected graph having five vertices of degrees 1, 1, 2, 2, 2. v 2 e 1 e 2 v 3 e 4 e 3 v 5 v4 Draw a graph with two connected components, having five vertices. e 1 v 2 e 2 v 3 e 3 v 5 v4 WUCT121 Graphs 23
For the following graph: e 1 e 2 v 2 v 4 v 6 v 7 e 3 e 4 e 5 e 6 e 7 v 3 v 5 v 8 o Write down the connected components H H H 1 2 3 = = = { v1, v2, v3}{, e1, e2, e3, e4 } { v4, v5, v6}{, e5, e6 } { v, v }{, e } 7 8 7 o Write down two simple paths from to v 3 and one that is not simple. Simple:, e2, v2, e3, v3 and v 1, e2, v2, e4, v3 Not simple: v 1, e1, v1, e2, v2, e3, v3 o List two pairs of vertices that are not connected. v 2 and v 4, v 6 and v 8 WUCT121 Graphs 24
1.7. Isomorphic Graphs Example: Consider the following graphs, are they the isomorphic, i.e. the same? No. The left-hand graph has 5 edges; the right hand graph has 6 edges. WUCT121 Graphs 25
Firstly, label the graphs. It looks true, so check all the things we know: v 5 v 4 v v' 1 1 v 3 v 2 v' 4 v' 2 G G v ' 3 v ' 5 Number of vertices: both 5. Number of edges: both 5. Degrees of corresponding vertices: all degree 2. Connectedness: Each is fully connected. Number of connected components: Both 1. Pairs of connected vertices: All correspond. Number of loops: 0. Number of parallel edges: 0. Everything is equal and so the graphs are isomorphic. WUCT121 Graphs 26
More formally: G = { V, E} where V = v, v, v, v, } and E = {( v = { e 1 1, v, e 2 2 ), ( v, e G = { V, E } 3 2, e 4, v 3, e 5 { 1 2 3 4 v5 ),( v } 3, v 4 ),( v 4, v 5 ),( v where V = { v, v, v, v v } E = {( v, v = { e, e, e, e, e } 1 1 2 2 ), ( v 3 2 4 3 5 1 2 3 4, 5 5, v and, v ),( v, v 3 4 ),( v 4, v 5 1 )} ),( v5, v1 )}. Construct 2 functions: f : V V and g : E E f : V V g : E E V V E E e 1 e 1 v 2 v 2 e 2 e 2 v 3 v 3 e 3 e 3 v 4 v 4 e 4 e 4 v 5 v 5 e 5 e 5 WUCT121 Graphs 27
1.7.1. Definition Let G = { V, E} and G = { V, E } be graphs. G and G are said to be isomorphic if there exist a pair of functions f : V V and g : E E such that f associates each element in V with exactly one element in V and vice versa; g associates each element in E with exactly one element in E and vice versa, and for each v V, and each e E, if v is an endpoint of the edge e, then f (v) is an endpoint of the edge g (e). Notes: To prove two graphs are isomorphic you must give a formula (picture) for the functions f and g. If two graphs are isomorphic, they must have: - the same number of vertices - the same number of edges - the same degrees for corresponding vertices - the same number of connected components - the same number of loops WUCT121 Graphs 28
- the same number of parallel edges. Further, - both graphs are connected or both graphs are not connected, and - pairs of connected vertices must have the corresponding pair of vertices connected. In general, it is easier to prove two graphs are not isomorphic by proving that one of the above properties fails. WUCT121 Graphs 29
Exercises: Show that the following graphs are isomorphic. These two graphs each have - 4 vertices - 6 edges - vertices of degree 1, 3, 4 and 4-1 connected component - 1 loop - 1 pair of parallel edges The graphs can be labelled to illustrate their isomorphism: e 1 e 3 e 2 e 4 v 2 v 4 e 6 v3 e 5 e' 1 v' 4 e' 2 v' 1 G G e' 6 e ' 3 e ' 4 v ' 2 v ' 3 e ' 5 WUCT121 Graphs 30
Draw all possible graphs having 2 edges and 2 vertices; that is, draw all non-isomorphic graphs having 2 edges and 2 vertices. e 1 e 2 v 2 e 1 e 1 v 2 e 1 v 2 v 2 e 2 e 2 e 2 Since isomorphic graphs are essentially the same, we can use this idea to classify graphs. WUCT121 Graphs 31
1.8. Regular, Complete and Complete Bipartite. 1.8.1. Definition: Regular. A simple graph G = { V, E} is said to be regular of degree k, or simply k-regular if for each v V, δ ( v) = k. That is, if a graph is k-regular, every vertex has degree k. Exercises: Draw all 0-regular graphs with 1 vertex; 2 vertices; 3 vertices. 1 vertex: 2 vertices: v 1 v 2 3 vertices: v 1 v 2 v 3 Draw all 1-regular graphs with 1 vertex; 2 vertices; 3 vertices; 4 vertices. 1 vertex and 3 vertices not possible 2 vertices v 2 4 vertices v1 v2 v3 v4 WUCT121 Graphs 32
Draw all 2-regular graphs with 2 vertices; 3 vertices; 4 vertices. 2 vertices, not possible, δ ( v) = 2 2 = 4 v V 2 n( E) = 4, n( E) = 2, thus need parallel edges 3 vertices v 2 v 3 4 vertices v 3 v 2 v 4 1.8.2. Definition: Complete. A simple graph G = { V, E} is said to be complete if each vertex of G is connected to every other vertex of G. The complete graph with n vertices is denoted K n. Notes: A complete graph is connected isomorphic n, two complete graphs having n vertices are For complete graphs, once the number of vertices is known, the number of edges and the endpoints of each edge are also known WUCT121 Graphs 33
Example: Draw K 5 v 5 v 2 v 4 v 3 Exercises: Draw K 1, K 2, K 3 and K 4. What is the degree of each vertex in each of the graphs drawn? K 1 : ( i ) 0 v 1 δ v = K2 : δ ( v i ) = v1 v2 1 K3 : δ ( v i ) = v 2 v 3 2 K4 : δ ( v i ) = 3 v 3 v 2 v 4 WUCT121 Graphs 34
Complete the following sentences: o A complete graph, K n, is an ( n 1) -regular graph. o A complete graph, K n, has n ( n 1) edges. [Use Euler s First Law: ( v) = 2n( E) Since K δ v V 2n n n ( v) = n( n 1) ( E) = n( n 1) ( ) 1 E = n( n 1) v V 1 2 has n vertices each of 2 δ.] degree ( n ) 1, WUCT121 Graphs 35
1.8.3. Definition: Bipartite. A simple graph G = { V, E} is said to be bipartite if there exists sets Notes: U V and W V, such that; 1. U W = V and U W = 2. every edge of G connects a vertex in U with a vertex in W. A bipartite graph G = { V, E} is one whose vertices can be separated into two disjoint sets, where every edge joins a vertex in one set to a vertex in the other u U, δ ( u) n( W ) and w W, δ ( w) n( U ) [ n (W ) is the number of elements in W] WUCT121 Graphs 36
Example: Consider the following graph G = { V, E}, where V = { u1, u2, w1, w2, w3}, is it bipartite? Yes u 1 u2 e 1 e 2 e 3 e 4 List the sets U and W. U = u 1, u } ; W = w, w, } Exercises: { 2 { 1 2 w3 Consider the following graphs, are they bipartite? If so write down the sets U and W. o w 1 w2 w3 u 1 u2 e 1 e2 w 1 w2 U = u 1, u } ; W = w 1, w } { 2 { 2 WUCT121 Graphs 37
o u 1 w 2 w 1 u 2 U = u 1, u }; W = w 1, w } { 2 { 2 Draw two bipartite graphs with 5 vertices. o Where U has 1 element and W has 4 elements. u 1 w1 w 2 w 3 w4 o Where U has 2 elements and W has 3 elements. u 1 u 2 w1 w 2 w 3 WUCT121 Graphs 38
1.8.4. Definition: Complete Bipartite. A simple graph G = { V, E}, is said to be complete bipartite if; Notes: 1. G is bipartite and 2. every vertex in U is connected to every vertex in W. A complete bipartite graph is one whose vertices can be separated into two disjoint sets where every vertex in one set is connected to every vertex in the other but no vertices within either set are connected. The symbol K n, m is used to denote the complete bipartite graph having n vertices in one set and m in the other. [Note that the comma is necessary!] u U, δ ( u) = n( W ) and w W, δ ( w) = n( U ) n ( E) = n m WUCT121 Graphs 39
Examples: Draw K 2, 2 Draw K 2, 3 K 2, 2 K 2,3 Exercises: Draw K 1, 3 K 1,3 Draw K 2, 4 K 2, 4 WUCT121 Graphs 40
Which of these graphs are bipartite. No w 3 u 1 w 1 u 3 u 2 Yes: U W = { u 1 = { w, u 1 2, w, u 2 3 }, w 3 } w 2 No WUCT121 Graphs 41
1.9. Eulerian Graphs. Problem 1: If you are walking in the park, can you cross each bridge exactly once? Does it depend on where you start? Could you do it with less bridges? Could you do it with more bridges? Problem 2: The Koenigsberg Bridge Problem. WUCT121 Graphs 42
Can you stroll around, crossing each bridge exactly once and return to your starting point? No one can do it. How do you prove it can't be done? If you're Leonhard Euler, you make some definitions, make the problem precise and prove a theorem! Redraw the problem as a graph: 1.9.1. Definition: Circuit. Let G = { V, E} be a graph and let v V. A circuit in G is a path from v to v in which no edge is repeated. Note: A circuit is a closed path and in many books is called a cycle. WUCT121 Graphs 43
Exercises: Write down the circuits in the following graph, starting at the given vertices. o v 2 : v2, e3, v3, e4, v2 o : v1, e1, v1 o v 3 : v3, e4, v2, e3, v3 o v 7 : None. 1.9.2. Definition: Eulerian Path Let G = { V, E} be a graph. A path in G is an Eulerian path if every edge of G is included once and only once in the path. WUCT121 Graphs 44
1.9.3. Definition: Eulerian Circuit Let G = { V, E} be a graph. A circuit in G is an Eulerian circuit if every edge of G is included exactly once in the circuit. 1.9.4. Definition: Eulerian Graph Let G = { V, E} be a graph. G is an Eulerian graph if G has an Eulerian circuit. Exercises: Which of these graphs are Eulerian? K 3 K 4 v 2 v 3 Yes v 3 v v 2 4 No v 5 v 2 K 5 v 4 v K 3 2, 3 Yes No WUCT121 Graphs 45
Can you find an Eulerian path in the following graph that is not an Eulerian circuit? e 1 v 2 e 6 e 4 e 2 v 3 v 5 e 5 v 4 e 3 v, e v e v e v e v e v e v 4 3, 3, 2, 2, 4, 4, 5, 5, 6, 1, 1, 2 Is the graph Eulerian? No. In the Koenisberg Bridge Problem, we wanted to start and end at the same vertex. That is, we need to prove that the graph K is not Eulerian. How? 1.9.5. Theorem: Euler's Theorem. Let G be a connected graph. G is an Eulerian graph if and only if the degree of each vertex is even. WUCT121 Graphs 46
For the Koenisberg Bridge Problem: δ ( C) = 3, so the graph is not Eulerian. Discussion: Is the connectedness condition in Euler's Theorem necessary? Consider the graph Each vertex has even degree but there is no Eulerian circuit. WUCT121 Graphs 47
In the Koenisberg Bridge setup, is it possible to cross each bridge exactly once without necessarily finishing where you start? That is, is there an Eulerian path in K? 1.9.6. Theorem: Existence of Eulerian Path. A connected graph has an Eulerian path, which is not a circuit, if it has exactly two vertices of odd degree. Example: δ ( A) = 3; δ ( B) = 5; δ ( C) = 3; δ ( D) = 3 There are more than 2 vertices of odd degree; therefore, K does not have an Eulerian path. WUCT121 Graphs 48
1.10. Trees and Spanning Trees. 1.10.1. Definition: Tree. A tree is a connected graph which has no non-trivial circuits. Notes: In a graph, a path consisting of a single vertex is a trivial circuit. A graph is a tree if and only if it is circuit free and connected. A tree can contain a trivial circuit, thus a single vertex is a tree. Exercise: Which of these graphs are trees? G 1 G4,, G 6 WUCT121 Graphs 49
Trees can be used in conjunction with connected graphs. 1.10.2. Definition: Spanning Tree. A spanning tree for a graph G is a sub-graph of G which is a tree that includes every vertex of G. Notes. A spanning tree of a graph G is a maximal tree contained in the graph G. When you have a spanning tree T for a graph G, you cannot add another edge of G to T without producing a circuit. Exercises: Can you have a spanning tree for a graph that is not connected? No, by definition, a tree is connected. Does every connected graph have a spanning tree? Yes. Are spanning trees unique in each graph? No. WUCT121 Graphs 50
If not, do two spanning trees for the same graph have anything in common? They have the same number of edges. Find all spanning trees for the following graph. (There are 12) WUCT121 Graphs 51
Example: Consider the following graph, G, representing pairs of people (A, B, C, D and E) who are acquainted with each other. B C G: E A D We wish to install the minimum number of phone lines so that communication between these people is maintained. As an adviser, you need to find a spanning tree T for G. B C B C B C E E E A T 1 D A T 2 D A T 3 D How many edges does each tree have? 4 Note: Any two spanning trees will have the same number of edges. WUCT121 Graphs 52
To make the problem more practical: Suppose the cost involved in installing each line is not the same. How do you find the network having the least cost? Begin by putting the cost (in $100) along each edge. This results in a weighted graph. B 3 C 5 G: 3.5 1 E A 3 D Calculating the cost for each tree: T 1 = 3 + 5 + 3.5 + 1 = 12.5 T 2 = 3 + 5 + 3.5 + 3 = 14.5 T 3 = 3 + 1 + 3 + 5 = 12 The tree with the lowest cost" is called the minimum spanning tree. In this case, the minimum spanning tree is T 3. WUCT121 Graphs 53
When the graph has a large number of vertices, it is not easy to find all spanning trees. In fact, we are not usually interested in finding all spanning trees for a graph. We would like an algorithm which finds the minimum spanning tree for a weighted connected graph. Kruskal's Algorithm is one such algorithm. 1.10.3. Definition: Weighted Graph A weighted graph is a graph for which each edge has an associated real number, called the weight of the edge. The sum of the weights of all of the edges is the total weight of the graph. A minimum spanning tree for a weighted graph is a spanning tree that has the least possible total weight when compared with all other spanning trees for the graph. Note. If G is a weighted graph and e is an edge, then we will use w(e) to represent the weight of the edge e and w(g) to represent the total weight of the graph G. WUCT121 Graphs 54
1.10.4. Kruskal's Algorithm Example. Find the minimal spanning tree for the following connected weighted graph G. The starting point of Kruskal's Algorithm is to make an edge list, in which the edges are listed in order of increasing weights. WUCT121 Graphs 55
Kruskal's Algorithm then includes the 3 additional columns as follows: The minimum spanning tree is drawn below. Note that there are 4 edges in the minimum spanning tree. If the weighted connected graph G has n vertices, then the minimum spanning tree will always have n 1 edges. Knowing this fact, we need not have checked whether the edges e 6, e7, e8 in the table included in the example created a circuit. WUCT121 Graphs 56
Kruskal's algorithm will always produce a minimum spanning tree for any connected weighted graph G. The idea of the Kruskal's algorithm for finding a minimum spanning tree T of G is: To examine the edges of G one by one in order of increasing weight. At each step, the edge being examined is added to the sub-graph S (which will be made up of the edges of T), if the addition of this edge to S does not create a circuit. After n 1 edges have been added to S (where n is the number of vertices), then the edges of S together with the vertices of the graph G produce the required tree T. WUCT121 Graphs 57
Kruskal's Algorithm for finding minimum spanning trees for weighted graphs (Epp's version) is then: Input: G a connected weighted graph with n vertices. Algorithm Body: (Build a sub-graph T of G to consist of all of the vertices of G with edges added in order of increasing weight. At each stage, let m be the number of edges of T.) 1. Initialise T to have all of the vertices of G and no edges. 2. Let E be the set of all edges of G and let m = 0. (pre-condition: G is connected.) 3. While ( m < n 1) a. Find an edge e in E of least weight. b. Delete e from E. c. If addition of e to the edge set of T does not produce a circuit then add e to the edge set of T and set m = m + 1 End While (post-condition: T is a minimum spanning tree for G.) Output: T (a graph) End Algorithm WUCT121 Graphs 58
1.10.5. Theorem: Kruskal s Output. When a connected weighted graph is input into Kruskal's algorithm, the output is a minimum spanning tree. The need to construct an ordered edge table before the algorithm begins and the need to check whether a circuit has been formed are two detriments to the computer implementation of Kruskal's algorithm. Exercises: Use Kruskal's algorithm to find a minimum spanning tree for the following graph. Draw the minimum spanning tree. v2 4 v 3 8 10 12 v 4 7 20 5 15 2 v 5 18 19 v 6 v 7 v8 13 WUCT121 Graphs 59
Edge Weight Will adding edge make circuit? Action taken Cumulative weight of sub-graph ( 4 v5 v, ) 2 No Added 2 ( 1 v3 v, ) 4 No Added 6 ( 2 v5 v, ) 5 No Added 11 ( 2 v4 v, ) 7 Yes Not added 11 ( 3 v7 v, ) 8 No Added 19 ( 3 v4 v, ) 10 No Added 29 ( 1 v2 v, ) 12 Yes Not Added 29 ( 7 v8 v, ) 13 No Added 42 ( 4 v8 v, ) 15 Yes Not Added 42 ( 5 v8 v, ) 18 Yes Not Added 42 ( 6 v8 v, ) 19 No Added 61 ( 2 v6 v, ) 20 Yes Not Added 61 WUCT121 Graphs 60
The minimum spanning tree is: v v2 1 v 3 v 4 v 5 v 6 v 7 v8 Let G be a connected graph. What can you say about an edge e of G if: o e is included in every spanning tree for G? e is not an edge in a circuit in G. o e is not included in any spanning tree for G? e is a loop. WUCT121 Graphs 61
1.11. Planar Graphs. Given a graph which is drawn with incidental crossings of edges, is it possible to determine whether an isomorphic graph could be drawn without any crossings of the edges? Exercises: Can either of these graphs be drawn with no incidental crossings? K 4 : v 1 v 3 v v 2 4 Yes v 4 v 3 v 2 K 3,3 No WUCT121 Graphs 62
1.11.1. Definition: Plane Graph. A graph G is said to be a plane graph if it is drawn in the plane in such a way that there are no incidental crossings of edges. Notes: A plane graph divides the plane into distinct regions called faces. a face. The outside of a plane graph is always considered Exercises: Number the faces in these graphs. 2 1 3 4 2 1 3 WUCT121 Graphs 63
1.11.2. Definition: Planar Graph. A graph G is said to be a planar graph if it can be drawn in the plane without incidental crossings of edges. Notes: A plane graph is a connected planar graph. 1.11.3. Theorem: Euler's Plane Graph Theorem. If G = { V, E} is a plane graph and if v equals the number of vertices, e equals the number of edges, and f equals the number of faces, then v e + f = 2. Exercises: Check Euler's Plane Graph Theorem for these graphs 1 2 3 v = 4, e = 5, f = 3 v e + f = 4 5 + 3 = 2 WUCT121 Graphs 64
WUCT121 Graphs 65 2 4 7 5 4 7, 5, = + = + = = = f e v f e v Re-draw so that there are no edges crossing: 2 4 6 4 4 6, 4, = + = + = = = f e v f e v The problem with applying this Theorem is that the graph has to be drawn as a plane graph before it can be applied. It does not help us decide if 3 3, K is a planar graph. 4 3 2 1 3 2 1 4
The following theorem includes a condition which can be checked in the original graph. 1.11.4. Theorem: Conditions of a Plane Graph. If G = { V, E} is a plane graph, without loops or parallel edges, v = n(v ), e = n(e) and v 3, then 1. e 3v 6, AND 2. if every circuit has at least 4 edges then e 2v 4. If the conditions of this theorem are also satisfied in any simple graph, G, then G may or may not be a planar graph. However, if they are not satisfied, then G is not a planar graph. WUCT121 Graphs 66
Exercises: Check the conditions for a plane graph for the following graph. 1. Check e 3v 6 e = 14, v = 8 3v 6 = 18 e < 3v 6 2. All circuits have at least 4 edges. Check all the circuits and that e 2v 4. 2v 4 = 12 e > 2v 4 Therefore we do not have a planar graph. WUCT121 Graphs 67
Decide whether these graphs are planar. o K 3,3 1. Check e 3v 6 e = 9, v = 6 3v 6 = 12 e < 3v 6 2. All circuits have at least 4 edges. Check that e 2v 4. 2v 4 = 8 e > 2v 4 Therefore this graph is not planar. WUCT121 Graphs 68
o v1 v 2 v 3 v 4 1. Check e 3v 6 e = 11, v = 7 3v 6 = 15 e < 3v 6 v 5 v6 v7 2. Some circuits have three edges. From this, we do not know whether the graph is planar or not. 3. Re-drawing the graph, we find it is planar. v 1 v 3 v v 5 6 v 7 v 4 v 2 WUCT121 Graphs 69
o v 5 v 2 v 4 v 3 This is the complete graph K 5 1. Check e 3v 6 e = 10, 3v 6 = 9 e v = 5 > 3v 6 Thus K 5 is not planar WUCT121 Graphs 70
1.11.5. Theorem: Smallest Non-Planar Graphs K 3,3 and K 5 are the smallest possible non-planar graphs. Further, a graph is non-planar if and only if it contains K 3, 3 or K 5 as a sub-graph. Example: v 5 v 2 v 3 v 8 v 6 v 4 v 7 The graph does not have 6 vertices of degree 3 and so cannot contain K 3, 3. The graph does not have 5 vertices of degree 4 and so cannot contain K 5. WUCT121 Graphs 71
Redrawing the graph without crossings: v 2 v 3 v 5 v 7 v 1 v 4 v 6 v 8 v = 8, e = 11, f = 5 v e + f = 8 11+ 5 = 2 WUCT121 Graphs 72