Graph Theory Notes
Graph Theory Notes
Graph Theory Notes
Kousha Etessami
U. of Edinburgh, UK
1 / 13
Overview
Graphs and Graph Models Graph Terminology and Special Types of Graphs Representations of Graphs, and Graph Isomorphism Connectivity Euler and Hamiltonian Paths Brief look at other topics like graph coloring
2 / 13
What is a Graph?
Informally, a graph consists of a non-empty set of vertices (or nodes), and a set E of edges that connect (pairs of) nodes. But different types of graphs (undirected, directed, simple, multigraph, . . .) have different formal denitions, depending on what kinds of edges are allowed. This creates a lot of (often inconsistent) terminology. Before formalizing, lets see some examples....
During this course, we focus almost exclusively on standard (undirected) graphs and directed graphs, which are our rst two examples.
3 / 13
ED
NY SF
LA
Only undirected edges; at most one edge between any pair of distinct nodes; and no loops (edges between a node and itself).
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 4 / 13
ED
NY SF
LA
Only directed edges; at most one directed edge from any node to any node; and loops are allowed.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 5 / 13
ED
NY SF
LA
Only directed edges; at most one directed edge from any node to any other node; and no loops allowed.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 6 / 13
An undirected multigraph:
ED
NY SF
LA
Only undirected edges; may contain multiple edges between a pair of nodes; but no loops.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 7 / 13
An undirected pseudograph:
ED
NY SF
LA
Only undirected edges; may contain multiple edges between a pair of nodes; and may contain loops (even multiple loops on the same node).
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 8 / 13
A directed multigraph:
ED
NY SF
LA
Only directed edges; may contain multiple edges from one node to another; but no loops allowed. Warning: this differs slightly from the Rosen book terminology. The books notion of directed multigraph would allow loops.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 9 / 13
An directed pseudograph:
ED
NY SF
LA
Only directed edges; may contain multiple edges from one node to another; and may contain loops (even multiple loops on one node).
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 10 / 13
We will focus on the two most standard types: (1.) graphs (simple undirected), and (4.) directed graphs (also known as digraphs).
1
A directed graph (digraph), G = (V , E ), consists of a non-empty set, V , of vertices (or nodes), and a set E V V of directed edges (or arcs). Each directed edge (u , v ) E has a start (tail) vertex u , and a end (head) vertex v . Note: a directed graph G = (V , E ) is simply a set V together with a binary relation E on V .
12 / 13
For a set V , let [V ]k denote the set of k -element subsets of V . (Equivalently, [V ]k is the set of all k -combinations of V .) A (simple,undirected) graph, G = (V , E ), consists of a non-empty set V of vertices (or nodes), and a set E [V ]2 of (undirected) edges. Every edge {u , v } E has two distinct vertices u = v as endpoints, and such vertices u and v are then said to be adjacent in the graph G. Note: the above denitions allow for innite graphs, where |V | = . In this course we will focus on nite graphs.
13 / 13
Applications of Graphs
#$%$&'()*NG *+ A G&A,)-
!labeled directed etc. ..." graph theory can be used in modelling of:
+ocial networks Communications networks *nformation networks +oftware design (ransportation networks .iological networks ......
groups.
/ertices represent indi/iduals or organi0ations edges
friendship graphs - undirected graphs where two people are connected if they are friends !e.g. on 2acebook" collaboration graphs - undirected graphs where two people are connected if they collaborate in a specific way influence graphs - directed graphs where there is an edge from one person to another if the first person can influence the second
*nformation Networks
*n a web graph web pages are represented
(ransportation Graphs
Graph models are e3tensi/ely used to study
transportation networks. Airline networks can be modeled using directed multigraphs where:
airports are represented by /ertices each flight is represented by a directed edge
from the /erte3 representing the departure airport to the /erte3 representing the destination airport
.iological Applications
Graph models are used e3tensi/ely in many
areas of the biological science. Niche overlap graphs model competition between species in an ecosystem:
Example: niche o/erlap graph for a forest ecosystem.
Solution: deg!a" ; 7 deg!b" ; < deg!d " ; 5 N!a" ; =b, f > N!b" ; =a, c, e, f > N!d" ; =c>.
)andshaking (heorem
THEOREM 1 (Handsha in! "emma#: *f G;!% $" is a undirected graph with m edges then:
2m =v V deg ( v )
Proof: Each edge contributes twice to the degree count of all vertices. Hence, both the left-hand and right-hand sides of this equation equal twice the number of edges. QED
)andshaking (heorem:$3amples
Example: )ow many edges are there in a graph with 56 /ertices each ha/ing degree si3: Solution: the sum of the degrees of the /ertices is A 56 ; A6. (he handshaking theorem says 7m ; A6. +o the number of edges is m ; B6. Example: *f a graph has C /ertices can each /erte3 ha/e degree B: Solution: (his is not possible by the handshaking thorem because the sum of the degrees of the /ertices B C ; 5C is odd.
4irected Graphs
Definition% (he in degree of a vertex v denoted deg!!v" is the number of edges directed into v. (he out degree of v denoted deg"!v", is the number of edges directed out of v. Note that a loop at a /erte3 contributes 5 to both in-degree and out-degree. Example% *n the graph G we ha/e
deg!!a" ; 7 deg!!b" ; 7 deg!!c" ; B deg!!d" ; 7 deg!!e" ; B deg!!f" ; 6.
Proof: (he first sum counts the number of outgoing edges o/er all /ertices and the second sum counts the number of incoming edges o/er all /ertices. .oth sums must be D$D.
.ipartite Graphs
Definition% An eFui/alent definition of a bipartite graph is one where it is possible to color the /ertices either red or blue so that no two ad9acent /ertices are the same color.
H is not bipartite: if we color a red then its neighbors f and b must be blue. .ut f and b are ad9acent.
G is bipartite
Example: +how that '() is not bipartite. Solution: *f we partition /ertices of '(B into two nonempty sets one set must contain two /ertices. .ut e/ery /erte3 is connected to e/ery other. +o the two /ertices in the same partition are connected. )ence '(B is not bipartite.
Examples%
+ubgraphs A subgraph of a graph G ; !V E" is a graph !* +" where W V and F E. A subgraph H of G is a proper subgraph of G if H , G& Example: here is K 5 and one of its !proper"
Definition% subgraphs:
*nduced +ubgraphs
Definition% ?et G ; !V E" be a graph. (he subgraph induced by a subset * of the /erte3 set V is the graph ); !* +" whose edge set + contains an edge in E if and only if both endpoints are in *& Example: )ere is -(C and its induced subgraph induced by * ; =a,b,c,e>.
/arriage0dating - /ertices represent men I women and edges link a man I woman if they are acceptable to each other as partners.
Bipartite graphs
A bipartite graph is a (undirected) graph G = (V , E ) whose vertices can be partitioned into two disjoint sets (V1 , V2 ), with V1 V2 = and V1 V2 = V , such that for every edge e E , e = {u , v } such that u V1 and v V2 . In other words, every edge connects a vertex in V1 with a vertex in V2 . Equivalently, a graph is bipartite if and only if it is possible to color each vertex red or blue such that no two adjacent vertices are the same color.
1/9
V1
V2
2/9
A matching, M , in a graph, G = (V , E ), is a subset of edges, M E , such that there does not exist two distinct edges in M that are incident on the same vertex. In other words, if {u , v }, {w , z } M , then either {u , v } = {w , z } or {u , v } {w , z } = . A maximum matching in graph G is a matching in G with the maximum possible number of edges.
3/9
Perfect/complete matchings
For a graph G = (V , E ), we say that a subset of edges, W E , covers a subset of vertices, A V , if for all vertices u A, there exists an edge e W , such that e is incident on u , i.e., such that e = {u , v }, for some vertex v . In a bipartite graph G = (V , E ) with bipartition (V1 , V2 ), a complete matching with respect to V1 , is a matching M E that covers V1 , and a perfect matching is a matching, M E , that covers V . Question: When does a bipartite graph have a perfect matching?
4/9
5/9
6/9
7/9
Case 2: Suppose, on the contrary, that there exists a nonempty strict subset S V1 with |S | = |NG (S )|. Any matching that covers V1 must match S to NG (S ). By the induction hypothesis, there is a matching M covering S on the bipartite subgraph G of G induced by S NG (S ). And furthermore, the bipartite subgraph G of G induced by (V1 S ) (V2 NG (S )) also satises the condition, and contains a matching M that covers (V1 S ). This is because if A V1 S has |A| > |NG (A)|, this implies |A S | > |NG (A S )|, which violates the assumption about G. Letting M = M M , M denes a matching in G that covers V1 .
8/9
More on Matchings
Corollary A bipartite graph G = (V , E ) with bipartition (V1 , V2 ) has a perfect matching if and only if |V1 | = |V2 | and S V1 , |S | |NG (S )|. Unfortunately, the proof we have given is not constructive enough: it doesnt yield an (efcient) algorithm to compute a maximum matching in a bipartite graph. An alternative proof of Halls theorem (which we do not give) based on alternating paths and augmenting paths, is constructive & yields an efcient (polynomial time) algorithm for computing a maximum matching.
9/9
Example:
Example:
&epresentation of Graphs:
Ad9acency Matrices
Definition: +uppose that G ; !V E" is a simple graph where DVD ; n. Arbitrarily list the /ertices of G as v(5 v(7 K v(n. (he ad1acenc$ matrix ' of G with respect to this listing of /ertices is the n 2 n 6-5 matri3 with its !i 1"th entry ; 5 when v(i and v(1 are ad9acent and ;6 when they are not ad9acent.
*n other words:
A =[ aij ]
and:
aij = a ji , i , j
Also since there are no loops each diagonal entry is 4ero5
aii =0 , i
represent graphs with loops and multi-edges. When multiple edges connect /ertices vi and v1 !or if multiple loops present at the same /erte3" the !i 1"th entry eFuals the number of edges connecting the pair of /ertices. Example: Ad9acency matri3 of a pseudograph using /erte3 ordering a b c d5
graphs in exactly the same way. The matrix A for a directed graph G = (V, E) has a 1 in its (i, j)th position if there is an edge from vi to vj, where v1, v2, vn is a list of the !ertices. "n other words,
aij =1 if (i , j ) E aij = 0 if (i , j ) E
Isomorphism of Graphs
Definition: Two (undirected) graphs G1 = (V1, E1) and G2 = (V2, E2) are isomorphic if there is a bijection, f : V 1 V 2 , with the property that for all ertices a , b V
{a ,b } E 1
if and only if
{f ( a ) , f ( b )} E 2
!uch a function f is called an isomorphism" Intuiti ely, isomorphic graphs are #T$% !&'%(, e)cept for #renamed( ertices"
Solution: (he function f with f!u5" ; v5 f!u7" ; v< f!uB" ; vB and f!u<" ; v7 is a one-to-one correspondence between V and *.
Solution: NoN +ince deg!a" ; 7 in G a must correspond to t u x or $, since these are the /ertices of degree 7 in ). .ut each of these /ertices is ad9acent to another /erte3 of degree 7 in H which is not true for a in G. +o G and ) can not be isomorphic.
Solution: (he function f is defined by: f!u5" ; vA f!u7" ; vB f!uB" ; v< f!u<" ; vC f!uC" ; v5 and f!uA" ; v7 is a bi9ection.
whether two graphs are isomorphic ha/e e3ponential worst-case time comple3ity !in the number of /ertices of the graphs". )owe/er there are algorithms with good time comple3ity in many practical cases. +ee e.g. a publicly a/ailable software called NA1(' for graph isomorphism.
Section Summary
1 / 20
Denition: For an undirected graph G = (V , E ), an integer n 0, and vertices u , v V , a path (or walk) of length n from u to v in G is a sequence: x0 , e1 , x1 , e2 , . . . , xn1 , en , xn of interleaved vertices xj V and edges ei E , such that x0 = u and xn = v , and such that ei = {xi 1 , xi } E for all i {1, . . . , n}. Such a path starts at u and ends at v . A path of length n 1 is called a circuit (or cycle) if n 1 and the path starts and ends at the same vertex, i.e., u = v . A path or circuit is called simple if it does not contain the same edge more than once.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 2 / 20
More on paths
When G = (V , E ) is a simple undirected graph a path x0 , e1 , . . . , en , xn is determined uniquely by the sequence of vertices x0 , x1 , . . . , xn . So, for simple undirected graphs we can denote a path by its sequence of vertices x0 , x1 , . . . , xn .
Note 1: The word simple is overloaded. Dont confuse a simple undirected graph with a simple path. There can be a simple path in a non-simple graph, and a non-simple path in a simple graph. Note 2: The terms path and simple path used in Rosens book are not entirely standard. Other books use the terms walk and trail to denote path and simple path, respectively. Furthermore, others use path itself to mean a walk that doesnt re-visit any vertex, except possibly the rst and last in case it is a circuit. To stick to Rosens terminology, we shall use the non-standard term tidy path to refer to such a walk.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 3 / 20
Example
d , a, b, c , f is a simple (and tidy) path of length 4. d , g , c , b, a, d is a simple (and tidy) circuit of length 5. a, b, g , f is not a path, because {b, g } is not an edge. d , a, b, c , f , b, a, g is a path, but it is not a simple path, because the edge {a, b} occurs twice in it. c , g , a, d , g , f is a simple path, but it is not a tidy path, because vertex g occurs twice in it.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 4 / 20
Ellen David
Fred
Bob
Alice
Kathy
5 / 20
7 / 20
Proposition
There is always a simple, and tidy, path between any pair of vertices u , v of a connected undirected graph G. Proof: By denition of connectedness, for every pair of vertices u , v , there must exist a shortest path x0 , e1 , x1 , . . . , en , xn in G such that x0 = u and xn = v . Suppose this path is not tidy, and n 1. (If n = 0, the Proposition is trivial.) Then xj = xk for some 0 j < k n. But then x0 , e1 , x1 , . . . , xj , ek +1 , xk +1 , . . . , en , xn is a shorter path from u to v , contradicting the assumption that the original path was shortest.
8 / 20
This graph, G = (V , E ), has 3 connected components. (It is thus a disconnected graph.) One connected component of G is H1 = (V1 , E1 ), where V1 = {d , a, b} and E1 = {{d , a}, {d , b}}.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 9 / 20
10 / 20
Example
d b e
This digraph, G, is not strongly connected, because, for example, there is no directed path from b to c . Question: what are the strongly connected components (SCCs) of G?
11 / 20
Example
d b e
This digraph, G, is not strongly connected, because, for example, there is no directed path from b to c . Question: what are the strongly connected components (SCCs) of G? One strongly connected component (SCC) of G is H1 = (V1 , E1 ), where V1 = {d , a, b} and E1 = {(d , a), (a, b), (b, d )}. Another SCC of G is H2 = (V2 , E2 ), where V2 = {e, c , f } and E2 = {(e, c ), (c , f ), (f , e)}. There are no other SCCs in G.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 11 / 20
This is a DAG
Kousha Etessami (U. of Edinburgh, UK)
Euler Paths and Euler Circuits Hamiltonian Paths and Hamiltonian Circuits
12 / 20
Question: Can you start a walk somewhere in Knigsberg, walk across each of the 7 bridges exactly once, and end up back where you started from?
13 / 20
Question: Can you start a walk somewhere in Knigsberg, walk across each of the 7 bridges exactly once, and end up back where you started from? Euler (in 1736) used graph theory to answer this question.
13 / 20
14 / 20
Eulers Theorem
Eulers Theorem (1736)
A connected undirected multigraph with at least two vertices has an Euler circuit if and only if each of its vertices has even degree. Proof: Only if direction: Suppose a multigraph G = (V , E ) has an Euler circuit, x0 e1 x1 e2 . . . em xm , where x0 = xm = u . For every vertex v V , v = u , each time we enter v via an edge ei , we must leave v via a different edge ei +1 . So, in total, since we see all edges incident to v exactly once, all such vertices v must have even degree. Likewise, the initial (and nal) vertex u = x0 = xm , must also have even degree, because the edges e1 and em pair up in the same way.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 15 / 20
18 / 20
Hamiltonian Paths
Denition: A Hamiltonian path in a (undirected) graph G is a simple path that visits every vertex exactly once. (In other words, it is a tidy path that visits every vertex.) A Hamiltonian circuit in a (undirected) graph G is a simple circuit that passes through every vertex exactly once (except for the common start and end vertex, which is seen exactly twice). Question: Is there a simple criterion for determining whether a (simple undirected) graph has a Hamiltonian path, or Hamiltonian circuit?
19 / 20
Hamiltonian Paths
Denition: A Hamiltonian path in a (undirected) graph G is a simple path that visits every vertex exactly once. (In other words, it is a tidy path that visits every vertex.) A Hamiltonian circuit in a (undirected) graph G is a simple circuit that passes through every vertex exactly once (except for the common start and end vertex, which is seen exactly twice). Question: Is there a simple criterion for determining whether a (simple undirected) graph has a Hamiltonian path, or Hamiltonian circuit? Answer: No. Nobody knows any efcient algorithm for determining whether a given (arbitrary) graph G has a Hamiltonian path/circuit. The problem is NP-complete.
Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 19 / 20
Ores Theorem
Every simple undirected graph, G = (V , E ), with n 3 vertices, in which deg (u ) + deg (v ) n for every two non-adjacent vertices u and v in V , has a Hamiltonian circuit.