FIT1058 Foundations of Computing - Graph Theory Notes

Graph Theory I

Introduction

  • Graphs are abstract models of networks used to represent systems with interacting components.
  • Examples include social networks, molecules, maps, electronic circuits, transport networks, the web, communication networks, software systems, and timetabling requirements.
  • Graphs consist of vertices (nodes) and edges (links) between pairs of vertices.
  • Graphs are abstractions that capture the structure of interactions while omitting details about how these interactions work.
  • Graph theory can be used to solve problems such as:
    • Identifying influential individuals or subcommunities in social networks.
    • Finding efficient routes between cities.
    • Embedding electronic circuits in silicon wafers without wire crossings.
    • Displaying computer networks with minimal edge crossings.
    • Determining possible train routes or exam timetables without clashes.
  • This chapter introduces basic concepts, vertex degrees, paths, and cycles.

11.1 Basic Definitions

  • A graph GG is a pair (V,E)(V, E), where VV is a set of vertices and EE is a set of unordered pairs of elements of VV (edges).
  • V(G)V(G) denotes the set of vertices of graph GG.
  • E(G)E(G) denotes the set of edges of graph GG.
  • An edge eEe ∈ E between vertices v,wVv, w ∈ V is the set v,w{v, w}.
  • Example graph G=(V,E)G = (V, E):
    • V=a,b,c,d,e,f,gV = {a, b, c, d, e, f, g}
    • E=a,b,a,c,b,c,c,d,f,gE = {{a, b}, {a, c}, {b, c}, {c, d}, {f, g}}
  • Two vertices v,wv, w are adjacent if v,wE{v, w} ∈ E, denoted as vwv ∼ w. If they are not adjacent, vwv \nsim w.
  • A neighbor of vertex vv is any vertex ww adjacent to vv. The set of all neighbors of vv is the neighborhood of vv.
  • Endpoints (endvertices) of an edge v,w{v, w} are vv and ww.
  • A vertex vv is incident with an edge ee if vv is one of the vertices in ee (i.e., e=v,xe = {v, x} for some vertex xx).
  • Two edges v,w{v, w} and v,x{v, x} are incident with each other if they share a common vertex vv (with wxw ≠ x).
  • A vertex is isolated if it is not incident with any edges (i.e., not adjacent to any other vertices).
  • A vertex is a leaf if it is incident with exactly one edge.
  • In the example graph in Figure 11.1:
    • Vertex cc is incident with edges a,c,b,c,c,d{a, c}, {b, c}, {c, d}.
    • Edge a,c{a, c} has endpoints aa and cc. It is incident with a,b,b,c{a, b}, {b, c}, and c,d{c, d}.
    • Edge f,g{f, g} is incident with vertices ff and gg, but not with any other edges.
    • Vertex ee is isolated.
    • Vertices d,fd, f, and gg are leaves.

11.2 Types of Graphs

  • Simple Graphs adhere to these conditions:
    • No vertex is adjacent to itself (no loops).
    • No two edges have the same pair of endpoints (no multiple edges).
  • Unless specified otherwise, graphs are assumed to be simple graphs.
  • Broader classes of graphs relax these conditions:
    • Loops: Edges whose endpoints are identical, connecting a vertex to itself.
    • Multiple Edges (Parallel Edges): More than one edge between a pair of vertices.
  • Weighted Graphs: Graphs with numbers assigned to each edge, representing length, size, or cost.
  • Undirected Graphs: Edges have no direction; the order of vertices in an edge v,w{v, w} does not matter.
  • Directed Graphs: Edges are ordered pairs (v,w)(v, w), representing a directed connection from vertex vv to vertex ww. Directed edges are called arcs.
  • Mixed/Hybrid Graphs: Graphs containing both directed and undirected edges.
  • Focus on simple (undirected) graphs:
    • They are relatively simple.
    • They appear as special cases in most other classes of graphs.
    • They are widespread as models of practical situations.
    • They capture main computational issues that arise in more general classes of graphs.

11.3 Graphs and Relations

  • Graphs are closely related to binary relations.
  • Adjacency is a binary relation defined on the set of vertices of a graph.
  • For undirected graphs, adjacency is a symmetric binary relation: if vv is adjacent to ww, then ww is adjacent to vv.
  • Adjacency is irreflexive: no vertex is adjacent to itself.
  • Simple graphs may be regarded as irreflexive symmetric binary relations.
  • Every simple graph gives rise to an irreflexive symmetric relation via adjacency.
  • Every irreflexive symmetric relation may be used to define a simple graph.
  • Discarding irreflexivity allows loops.
  • Discarding symmetry yields directed graphs.
  • Discarding both results in a directed graph that may have loops but no multiple edges, allowing the reverse edge (w,v)(w, v) for an existing edge (v,w)(v, w).
  • Any binary relation can be regarded as a directed graph, possibly with loops but no multiple edges.

11.4 Representing Graphs

  • Graphs can be displayed as diagrams but formal symbolic representations are needed for large graphs and computer storage.
  • Four main ways of representing graphs symbolically:
11.4.1 Edge List
  • An edge list is a list of the edges in a graph.
  • The order of edges typically does not matter.
  • To completely represent a graph, specify both the vertex set and the edge set.
  • An edge list does not necessarily group edges by shared vertices, which may be less efficient for some task
11.4.2 Adjacency Matrix
  • The adjacency matrix of a graph GG is an n×nn × n array AA of bits, where nn is the number of vertices.
  • Rows and columns correspond to vertices.
  • The entry in the vv-row and ww-column of AA is:
    • 1, if vwv ∼ w
    • 0, if vwv \nsim w
  • Entries represent the number of edges between two vertices (0 or 1 for simple graphs).
  • Observations about the adjacency matrix:
    • The main diagonal entries are all 0 (no self-loops).
    • The matrix is symmetric about the main diagonal (for undirected graphs).
  • The number of 1s in the vv-row (or vv-column) captures information about vertex vv.
  • The number of 1s in the entire adjacency matrix is twice the number of edges.
  • The rules for adjacency matrices can be relaxed for wider classes of graphs, such as allowing loops that would turn some of the diagonal entries into 1s. For directed graphs, the entry in row vv and column ww need not equal the entry in row ww and column vv.
  • Mathematical operations on adjacency matrices can reveal aspects of graph structure and are used in some algorithmic problems.
  • One virtue of the adjacency matrix is that you can efficiently test whether or not two given vertices are adjacent.
  • The adjacency matrix takes the same amount of space regardless of how many edges the graph has.
  • If dealing with sparse graphs, the adjacency matrix representation may take up too much space in memory.
11.4.3 Adjacency List
  • An adjacency list specifies the vertices in some order and, for each vertex, provides a list of all adjacent vertices.
  • For example, the graph GG in Figure 11.1 has the following adjacency list representation:
    • a:b,ca : b, c
    • b:a,cb : a, c
    • c:a,b,dc : a, b, d
    • d:cd : c
    • e:e :
    • f:gf : g
    • g:fg : f
  • From the adjacency list, one can readily see that cc is adjacent to a,ba, b, and dd, the neighborhood of cc is a,b,d{a, b, d}, ee has no neighbors, and the graph has three leaves: d,fd, f, and gg.
  • This representation enables efficient searching of neighborhoods of vertices and is compact compared to the adjacency matrix.
11.4.4 Incidence Matrix
  • The incidence matrix of a graph GG is an m×nm × n array AA of bits, where mm is the number of edges and nn is the number of vertices.
  • Rows correspond to edges, and columns correspond to vertices.
  • The entry in the ee-row and vv-column is:
    • 1, if ee is incident with vv
    • 0, if ee is not incident with vv
  • As with the adjacency matrix, certain matrix operations can be done with it in order to study the graph.
  • This representation is seldom used in computers, but is theoretically important.

11.5 Subgraphs

  • A subgraph of a graph G=(V,E)G = (V, E) is a graph F=(U,D)F = (U, D) such that UVU ⊆ V and DED ⊆ E.
  • FGF ≤ G denotes that FF is a subgraph of GG.
  • A graph is a subgraph of itself: GGG ≤ G.
  • FF is a proper subgraph of GG if FGF ≤ G and FGF ≠ G, denoted as F < G.

11.6 Some Special Graphs

  • The complete graph on nn vertices, denoted by KnK_n, has every pair of vertices joined by an edge.
  • The null graph on nn vertices, denoted by KnK_n, has no edges.
  • The path graph of length n1n−1, denoted by Pn1P_{n−1}, has nn vertices and n1n−1 edges such that vertices can be sequenced so that two vertices are adjacent if and only if they are consecutive in the sequence.
  • The cycle of length nn, denoted by CnC_n, has nn vertices and nn edges and is formed from a path graph by adding an edge between the first and last vertices of the path.

11.7 Degree

  • The degree of a vertex is the number of neighbors it has, which is also the number of edges incident with the vertex (for simple graphs).
  • degG(v)\text{deg}_G(v) denotes the degree of vertex vv in graph GG. If the graph is clear from context, it may be written as deg(v)\text{deg}(v).
  • A vertex is isolated if and only if it has degree 0.
  • A vertex is a leaf if and only if it has degree 1.
  • If nn is the number of vertices, the degrees can be any of 0,1,2,,n10, 1, 2, …, n − 1.
Theorem 56
  • In every graph, there are two vertices with the same degree.
  • Proof by cases:
    • Case 1: If GG does not have a vertex of degree n1n−1, possible degrees are 0,1,2,,n20, 1, 2, …, n−2. Since there are only n1n−1 different numbers in this list, but there are nn vertices, at least two must have the same degree.
    • Case 2: If GG has a vertex vv of degree n1n−1, then vv is adjacent to all other vertices. Therefore all other vertices have vv as a neighbor, so their degrees are all greater than or equal to 1. Thus, all the degrees of all the vertices of GG must be in the set 1,2,,𝑛1{1, 2,…,𝑛 − 1}. This means there are only n1n−1 possible degrees that a vertex of GG can have. But there are nn vertices in GG. Therefore there must be at least two vertices in GG that have the same degree.
Theorem 57 (Handshaking Lemma)
  • For every graph G=(V,E)G = (V, E), the sum of the degrees of the vertices is twice its number of edges:
  • vVdeg(v)=2m\sum_{v ∈ V} \text{deg}(v) = 2m, where mm is the number of edges of GG.
  • Proof: Each edge contributes 1 to the degree of each of its two endpoints. Thus, each edge is counted twice when summing the degrees of all vertices.
Corollary 58
  • For any graph GG, average degree of G=2mnG = \frac{2m}{n}, where nn is number of vertices and mm is number of edges.
  • Proof: average degree of G=sum of degreesnumber of vertices=vV(G)deg(v)n=2mnG = \frac{\text{sum of degrees}}{\text{number of vertices}} = \frac{\sum_{v ∈ V(G)} \text{deg}(v)}{n} = \frac{2m}{n}.
  • The average degree can range from 0 (for a graph with no edges) to n1n−1 (for a complete graph on nn vertices).
Corollary 59
  • Every graph has an even number of vertices of odd degree.
  • Proof: The sum of all degrees is even (by Theorem 57). The sum of even degrees is even. Therefore, the sum of odd degrees must be even. The sum of an even number of odd numbers is even, while the sum of an odd number of odd numbers is odd. It follows that there must be an even number of odd degrees.

11.8 Moving Around

  • A walk from vertex vv to vertex ww is a sequence of vertices and edges:
  • v<em>0,e</em>1,v<em>1,e</em>2,v<em>2,,v</em>k1,e<em>k,v</em>kv<em>0, e</em>1, v<em>1, e</em>2, v<em>2, …, v</em>{k−1}, e<em>k, v</em>k, where
    • v0=vv_0 = v (starts at vv)
    • vk=wv_k = w (finishes at ww)
    • each viv_i is a vertex of GG
    • each eie_i is an edge of GG
    • i:e<em>i=v</em>i1,v<em>i∀i: e<em>i = {v</em>{i−1}, v<em>i} (edge e</em>ie</em>i links vertices v<em>i1v<em>{i−1} and v</em>iv</em>i)
  • The length of a walk is the number of edges in it.
  • The shortest possible walk is of length zero, consisting of a single vertex and no edges.
  • Two freedoms in walking around a graph:
    • Vertices can be visited more than once.
    • Edges can be traversed more than once, possibly in different directions.
  • For simple graphs, a walk can be specified by just listing the vertices in order:
    • v=v<em>0,v</em>1,v<em>2,,v</em>k1,vk=wv = v<em>0, v</em>1, v<em>2, …, v</em>{k−1}, v_k = w
  • If the graph has multiple edges, specifying the edges is necessary.
  • A walk is closed if its start and end vertices are the same (i.e., v=wv = w).
  • A trail is a walk in which no edge is used more than once.
  • A closed trail is a closed walk that is also a trail.
  • A path is a trail in which no vertex or edge is repeated.
  • The distance between two vertices is the length of the shortest path between them.
Theorem 60
  • Let GG be any graph. GG has an odd closed walk if and only if it has an odd cycle.
  • Proof:
    • (⟹) If GG has an odd cycle, every cycle is a closed walk. So an odd closed cycle is an odd closed walk. Therefore GG has an odd closed walk.
    • (⟸) Suppose GG has an odd closed walk. Let WW be the shortest odd closed walk in GG. The sequence of vertices of WW may be written as v<em>0,v</em>1,v<em>2,,v</em>k1,v<em>k=v</em>0v<em>0, v</em>1, v<em>2,…,v</em>{k−1}, v<em>k = v</em>0, where kk is odd. If no vertex of GG except the start/end vertex repeats in WW, then WW is already an odd cycle, and we are done. Assume, by way of contradiction, that there is a vertex that is repeated in WW. Let v<em>iv<em>i be the first vertex in this shorter list that appears again later in the list as v</em>jv</em>j. So v<em>i=v</em>jv<em>i = v</em>j, and 0≤i<j≤k−1. Using the vertices v<em>iv<em>i and v</em>jv</em>j, we can divide the closed walk WW into two shorter closed walks: v<em>i,v</em>i+1,,v<em>j1,v</em>jv<em>i, v</em>{i+1},…,v<em>{j−1}, v</em>j and v<em>j,v</em>j+1,,v<em>k1,v</em>0,v<em>1,,v</em>i1,viv<em>j, v</em>{j+1},…,v<em>{k−1}, v</em>0, v<em>1,…,v</em>{i−1}, v_i. Recall that the length of WW is odd. Since we just divided WW into two “subwalks”, the length of WW must equal the sum of the lengths of those two subwalks. Therefore, one of those subwalks has odd length and the other has even length. Both are closed walks, so the one that has odd length is an odd closed walk. Since both the subwalks are shorter than WW, we have constructed an odd closed walk in GG that is shorter than WW.
  • A cycle in a graph is Hamiltonian if it includes every vertex.
  • Hamiltonian cycles are used in planning routes which must visit every location in some set, without visiting any location twice, and returning to the starting point.
  • The problem of finding the Hamiltonian cycle of minimum total cost is known as the Travelling Salesman Problem (TSP).

11.9 Connectivity

  • Two vertices vv and ww in a graph GG are connected if there is a path from vv to ww in GG.
  • A graph GG is connected if, for every pair of vertices vv and ww, there is a path from vv to ww in GG.
  • A component of GG is a maximal connected subgraph of GG.
  • Connectivity defines an equivalence relation RR on the vertices VV of a graph G=(V,E)G = (V, E):
    • For all v,wV,vRwv, w ∈ V, vRw if and only if there is a walk from vv to ww in GG.
    • This relation is reflexive, symmetric, and transitive.
  • The equivalence classes of RR partition VV and are the vertex sets of the components of GG.

11.10 Bipartite Graphs

  • A graph G=(V,E)G = (V, E) is bipartite if its vertex set VV can be written as a disjoint union V=ABV = A ⊔ B such that every edge has one endpoint in AA and the other in BB.
  • A complete bipartite graph is a bipartite graph in which every pair of vertices on different sides is adjacent.
  • If the two sides have pp and qq vertices then we denote the complete bipartite graph by Kp,qK_{p,q}.
Theorem 61
  • A graph is bipartite if and only if it has a 2-coloring (a function that assigns one of two colors to each vertex such that adjacent vertices have different colors).
    • (⟹) Suppose GG is bipartite, and let AA and BB be the two sides, so all edges have one endpoint in AA and the other in BB. Define a function which colours all vertices in AA Black and all vertices in BB White. Then every edge has one endpoint coloured Black (because it is in AA) and the other endpoint coloured White (because it is in BB). Therefore adjacent vertices always get different colors. Therefore this function is a 2-colouring of GG.
    • (⟸) Suppose G=(V,E)G = (V,E) has a 2-colouring fVBlack,Whitef∶V→{Black,White}. Let A=f1(Black)A=f^{−1}(Black) be the set of all vertices coloured Black, and let B=f1(White)B=f^{−1}(White) be the set of all vertices coloured White. Every vertex of VV belongs to one of these two sets, since every vertex is mapped to one of those two colours. Furthermore, no vertex can belong to both sets, because ff is a function and therefore cannot assign two different values to any element of its domain. Therefore V=ABV = A⊔B. Also, since adjacent vertices get different colours under ff, adjacent vertices must belong to different sets (AA or BB); they cannot both belong to the same set, for then they would be given the same colour by ff.
Theorem 62
  • A graph is bipartite if and only if it has no odd closed walk.
    • (⟹) If GG is bipartite, then every walk must alternate between vertices in AA and vertices in BB. So, it goes from a vertex in AA, to a vertex in BB, to one in AA, to one in BB, and so on, possibly with repetition of vertices and edges. At every stage, if we are at a vertex in AA, then two steps later we are back in AA. This alternation ensures that a closed walk has even length. Therefore GG has no odd closed walk.
    • (⟸) If GG has no odd closed walk, then for each component of GG: choose one vertex in the component as the “ground vertex” of that component. Call it gg. Colour gg Black. Then colour every other vertex vv of the component as follows: Colour of vv = Black, if the distance from gg to vv is even; White, if the distance from gg to vv is odd. Assume, by way of contradiction, that our assignment of colours is not a 2-colouring of GG. Then there must be two adjacent vertices that get the same colour. Let XX be this colour, which could be Black or White. Let vv and ww be these two adjacent vertices, each with colour XX. Since they are adjacent, they must belong to the same component of GG. Let gg be the ground vertex for that component. Key observation: the distances from gg to vv, and from gg to ww, have the same parity. Since these two distances have the same parity, their sum is even. Let PP be a shortest path in GG from gg to vv, and let QQ be a shortest path in GG from gg to ww. The lengths of these two paths have the same parity, as explained in the previous paragraph. So length of PP + length of QQ is even. Now consider the walk formed by starting at vv, going along PP to vv, then stepping along edge v,w{v,w} to ww, then going along QQ from ww back to gg, finishing up at gg. This is a closed walk, since it finishes where it starts. Its length is length of PP + length of QQ + 1, where we now have an extra +1 because of the edge v,w{v,w}. We have already seen that the sum of the lengths of PP and QQ is even. It follows that the length of this closed walk is odd. So we have constructed an odd closed walk in GG.
Corollary 63
  • A graph is bipartite if and only if it has no odd cycle.

11.11 Euler Tours

  • An Euler tour is a closed trail that uses every edge exactly once and finishes at its starting vertex.
Theorem 64 (Euler, 1736)
  • A connected graph GG has an Euler tour if and only if every vertex has even degree.
    • (⟹) Let GG be a connected graph with an Euler tour. An Euler tour is a trail, and when a trail passes through a vertex, it uses two of the edges incident with that vertex: one on the way in, and one on the way out. An Euler tour uses each edge of the graph exactly once. It follows that it must revisit each vertex as many times as necessary in order to use each of its incident edges exactly once, and it uses two edges for each visit, so the number of incident edges at the vertex must be a multiple of 2. Therefore each vertex degree is even.
    • (⟸) Let GG be a connected graph in which every vertex has even degree. We give an algorithm for constructing an Euler tour for GG. Initialisation: Choose any vertex vv of GG. Let TT be the trivial closed trail consisting just of the vertex vv, with no edges.While there is at least one edge we have not yet used in TT: Find a vertex in TT that has at least one edge that we have not yet used in TT. Call it vv.Walk along an edge incident at vv Starting anywhere on TT, we follow TT until we first reach vv. Then we follow UU all the way until we return to vv for the last time, having stepped along all edges of UU. Then we resume following TT, and we follow it all the rest of the way until we return to our starting vertex for the last time, having used every vertex of TT.
  • A graph is Eulerian if it contains an Euler tour.
Theorem 65
  • For any kNk ∈ ℕ, the edges of a graph can be partitioned into kk trails if and only if the graph has at most 2k2k vertices of odd degree.
  • The open trails in such a partition start and end at odd-degree vertices.

11.12 Exercises

  • Exercise questions about:
    • Predicate logic expressions for graph properties.
    • Bit representation of graphs using different methods.
    • Rewriting the proof of Theorem 56.
    • Calculating edges and average degree of a caffeine molecule graph.
    • Proving shortest walks are paths.
    • Graphs with cycles and triangle inequality.
    • 2-colorings of bipartite graphs.
    • Trails and Euler tours in multigraphs.
    • Hamiltonian and Eulerian cycles in platonic solids.
    • Hamiltonian cycle construction in bit string graphs.
    • Extending Theorem 64 to multigraphs.