Chapter 01 - Graphs
Chapter 01 - Graphs
Graphs
Introduction
For years, mathematicians have affected the growth and development of computer science.
In the beginning they helped design computers for the express purpose of simplifying large
mathematical computations.
Mathematicians study graphs because of their natural mathematical beauty with relations to
topology, algebra and matrix theory spurring their interest. Computer scientists also study
graphs because of their many applications to computing, such as in network design. These
applications have generated considerable interest in algorithms dealing with graphs and
graph properties by both mathematicians and computer scientists.
Today, a study of graphs is not complete without at least an introduction to both theory and
algorithms. This text will attempt to convince you that this is simply the nature of the subject
and, in fact, the way it was meant to be treated.
These intervals may or may not have a nonempty intersection. Suppose that we want a way
to display the intersection relationship among these intervals. What form of model will easily
display these intersections?
One possible model for representing these intersections is the following: Let each interval be
represented by a circle and draw a line between two circles if, and only if, the intervals that
correspond to these circles intersect.
Next, we consider the following old puzzle. Suppose there are three houses (call them h , h 1 2
and h ) and three utility companies (say gas (g), water (w) and electricity (e)). Our problem
3
is to determine if it is possible to connect each of the three houses to each of the three
utilities without crossing the service lines that run from the utilities to the houses. We model
this puzzle by representing each house and each utility as a circle and drawing a line
between two circles if there is a service line between the corresponding house and utility. A
solution to this problem would be a drawing in which no lines crossed.
Despite the fact that these problems seem very different, we have used a similar type of
diagram to model them. Such a diagram is called a graph.
One of the beauties of graphs is that they may be thought of in many ways: formally as set
systems, geometrically as the diagrams and algebraically. Such diverse representations
afford us an opportunity to use many tools in studying graphs. To do this effectively, we need
to build more terminology and mathematical machinery.
Given a graph G = (V , E), the number of vertices in V is called the order of G and the
number of edges in E is called the size of G. They are denoted as |V | and |E|, respectively.
If a graph G has order p and size q, we say G is a (p, q) graph.
Two vertices that are joined by an edge are said to be adjacent, as are two edges that meet
at a vertex. If two vertices are not joined by an edge, we say they are nonadjacent or
independent. Similarly, two edges that do not share a common vertex are said to be
independent. The set of all vertices adjacent to a vertex v is called the neighborhood of v
and is denoted N (v).
An edge between vertices u and v is said to have u(or v) as an end vertex. Further, the
edge is said to be incident with v (or with u) and v is said to dominate u (also, u dominates
v). The number of edges incident with a vertex v is called the degree of v and is denoted
deg vor by deg v if we wish to emphasize that this occurs in the graph G. The minimum
G
degree and maximum degree of a vertex in the graph G are denoted by δ(G) and Δ(G),
respectively.
A graph in which each vertex has degree r is called an r-regular graph (or simply regular).
We now present the theorem traditionally called The First Theorem of Graph Theory.
∑ deg v i = 2q.
i=1
Proof:
Since each edge has exactly two end vertices, the sum of the degrees counts each
edge exactly twice. Thus, the sum is obtained. Since 2q is even, an even number of
vertices of odd degree must then be present in the sum. ■
Mathematicians use the term isomorphism to mean the "fundamental equality" of two objects
or systems. That is, the objects really have the same mathematical structure, only
nonessential features like object names might be different. For graphs, "fundamentally
equal" means the graphs have essentially the same adjacencies and nonadjacencies.
To formalize this concept further, we say two graphs G and G are isomorphic if there
1 2
exists a one-one and onto function f : V (G ) → V (G ) such that xy ∈ E(G ) if and only if
1 2 1
to express the correspondence between vertices that are "essentially the same" in the two
graphs. The function f is called an isomorphism.
A subgraph of G is any graph H such that V (H ) ⊂ V (G) and E(H ) ⊂ E(G); we generally
say G contains H . If H is a subgraph of G and V (H ) = V (G), we say that H is a spanning
subgraph of G. A more restricted but often very useful idea is the following: Given a subset
S of V (G), the subgraph induced by S, denoted ⟨S⟩, is that graph with vertex set S and
edge set consisting of those edges of G incident with two vertices of S . So, an induced
subgraph keeps both adjacency and non-adjacency of the inducing vertices, in contrast to
an ordinary subgraph that preserves only non-adjacency.
Several natural and useful variations on graphs will be helpful. The first is the idea of a
multigraph, that is, a graph with (possibly) multiple edges between vertices.
A pseudograph allows edges that begin and end at the same vertex (called a loop). If we
think of the edge between two vertices as an ordered pair rather than a set, a natural
direction from the first vertex of the pair to the second can be associated with the edge.
Such edges will be called arcs, and graphs in which each edge has such a direction will be
called directed graphs or digraphs.
For digraphs, the number of arcs directed away from a vertex v is called the outdegree of v
(denoted od v) and the number of arcs directed into a vertex v is the indegree of v (denoted
). Often, for emphasis, we denote the arc directed from u to v as u → v. In a digraph, we
id v
In this text, the term graph will always be as we defined it: finite order, without loops, multiple
edges or directed edges.
Let x and y be two vertices of a graph G (not necessarily distinct vertices). An x − y walk in
G is a finite alternating sequence of vertices and edges that begins with the vertex x and
ends with the vertex y and in which each edge in the sequence joins the vertex that
precedes it in the sequence to the vertex that follows it in the sequence. The number of
edges in a walk is called the length of the walk. Note that repetition of vertices and edges is
allowed. An x − y walk is closed if x = y and open otherwise. Two walks are equal if the
sequences of vertices and edges are identical.
Several stronger types of walks are also important. An x − y trail is an x − y walk in which
no edge is repeated, and an x − y path is an x − y walk in which no vertex is repeated.
Clearly, a path is also a trail. We consider a single vertex as a trivial path (walk or trail). It is
clear that every path is a trail and every trail is a walk and that the converse of each of these
statements fails to hold.
Theorem:
In a graph G, every x − y walk contains an x − y path.
A closed trail is called a circuit, while a closed path is called a cycle. A graph of order n that
consists of only one cycle (or path) is denoted C (or P ) and is called simply the n-cycle (or
n n
n-path). If a graph contains no cycles it is termed acyclic. One special class of graphs is
called complete graphs, which contain an edge between all pairs of vertices. We denote
the complete graph of order p as K . p
We say a graph G is connected if there exists a path in G between any two of its vertices
and G is disconnected otherwise. A component of a graph is a maximal connected
subgraph.
Connectivity in digraphs is a little more interesting in that there are several possible kinds.
A digraph D is said to be strongly connected (or strong) if for each vertex v of D there
exists a directed path from v to any other vertex of D. We say D is weakly connected (or
weak) if, when we remove the orientation from the arcs of D, a connected graph or
multigraph remains (often, we say that the underlying graph is connected). Of course, D is
disconnected if it is not at least weakly connected.
We define a tree to be a connected acyclic graph; a forest is an acyclic graph, that is, a
graph each of whose components is a tree. (What else would a forest be?)
In defining a forest as a collection of trees, what we have done is form a new graph from
other graphs. In particular, the union of two graphs G and G is that graph G with
1 2
Graph union is an example of one graph operation used to form a new graph from other
graphs. Perhaps the simplest and most natural graph operation is the following:
–
–
Consider a graph
G = (V , E) G V (G) = V (G) and form a new graph where and an edge
–
–
e ∈ E(G) e E(G) G Gif and only if is not in . We call the complement of . In a sense, all we
have done is remove all the edges from G and insert those edges that were originally
–
G G G missing from . It should also be clear that the complement of is the graph itself.
The join of two graphs G and H , denoted G + H , is the graph consisting of G ∪ H and all
edges between vertices of G and vertices of H . Often, we will have occasion to consider the
special case when H = K and for simplicity, we will denote this as G + x, where K is the
1 1
vertex x.
–
–
K m,n We define the complete bipartite graph
Km + Kn to be the join . Complete bipartite
graphs are a special case of an important class of graphs. We say a graph G is bipartite if it
is possible to partition the vertex set V into two sets (called partite sets), say V and V ,
1 2
Clearly complete bipartite graphs are bipartite, but complete bipartite graphs contain all
possible edges between the partite sets. More generally, a graph G is n-partite if it is
possible to partition the vertex set of G into n sets, such that any edge of G joins two
vertices in different partite sets. Complete n-partite graphs have all possible edges between
the partite sets. We denote the complete n-partite graph with partite sets of order
p1 , p2 , … , pn as K p 1 ,p 2 ,…,p n .
On the other hand, at times we will also remove a set S of vertices from a graph G, along
with all edges of G incident to a vertex in S . We denote the resulting graph as G − S . Again,
if S = {x}, we denote the resulting graph as G − x.
The lexicographic product (sometimes called the composition) of two graphs G and G 1 2,
adjacency matrix of G is clearly a symmetric (0, 1)-matrix, with zeros down the main
diagonal. The adjacency matrix clearly contains all the structural information about G and
thus can be used as a representation for G.
This representation has several advantages. First, (0, 1)-matrices are well-studied objects,
and we gain all the power of linear algebra as a tool for studying graphs. Second, the
adjacency matrix representation is a very convenient one for storage within a computer.
We now determine a method for finding the number of x − y walks of a given length in a
graph.
Theorem:
If A is the adjacency matrix of a graph G with vertices v , v , … , v , then the (i, j)-entry 1 2 p
Proof:
We will apply induction on the length n. For n = 1, the result is obvious, as this is just
the adjacency matrix itself. Now let A = [a ] and assume that a
n−1
is the number of
n−1
ij
n−1
ij
k=1
Every v − v walk of length n in G must consist of a v − v walk of length n − 1
i j i k
followed by the edge from v to v and the vertex v . Thus, by induction and equation
k j j
An idea similar to that of the adjacency matrix is the incidence matrix. For a (p, q) graph G,
let the p × q matrix M = [i ] be defined as follows: i = 1 if vertex x is incident to edge e
xe xe
and i = 0 otherwise.
xe
Thus, the rows of M correspond to the vertices of G and the columns correspond to the
edges. It is easy to see that all the structure of G is contained in M ; however, because M is
not square, it lacks some of the power of adjacency matrices. Despite this shortcoming,
incidence matrices have some valuable uses.
Probably the most commonly used form is merely to list each vertex in V along with those
vertices that are adjacent to the listed vertex. This adjacency list contains all the structure
of G, but has no extraneous information about nonadjacencies (like the zeros of the
adjacency matrix). Nonadjacency is implied by omission from the list. Thus, when using an
adjacency list, a program does not need to decide whether or not the next piece of
information shows an edge or a nonedge, but rather it just retrieves the next adjacency.
Algorithms
In order to deal with graphs efficiently and actually determine their properties on a computer,
we need to develop processes that, when applied to a particular graph, will produce the
desired answer. Usually, a graph problem will be posed in terms of several parameters (or
variables). We then describe the problem at hand by giving a specification of the parameters
involved and a statement about what constitutes a solution. An instance of a problem is
obtained when we specify values for the parameters.
The problem we will be more concerned with is the time complexity, that is, the relative
time it will take us to perform the algorithm. We speak of relative time because it is
impractical to try to determine the exact running times of algorithms. Thus, an upper bound
on the time complexity of the problem is usually obtained.
Consider as an example the problem of computing the square of the adjacency matrix A of a
graph of order p. If we follow the typical rules for matrix multiplication, we perform p
multiplications and p − 1 additions to compute each entry of A . Since there are p entries in
2 2
its task.
In judging the quality of an algorithm, we try to measure how well it performs on arbitrary
input. In doing this, we try to find an upper bound on the number of computational steps
necessary to perform this algorithm. As in the description of matrix multiplication, this is
usually a function of the size of the problem. Here, size only refers to the amount of data in
the instance of the problem at hand. Since it is clear that we must compute more if we have
more data, it only makes sense for us to measure our work as a function of the problem size.
Returning to the problem of squaring the adjacency matrix A, if c is the maximum amount of
1
time required to multiply two numbers and c is the maximum amount of time necessary to
2
add two numbers, and c is the maximum amount of time necessary to do all the other steps
3
necessary for us to perform the algorithm, then we can bound the time, T (p), it takes to
square the adjacency matrix A (or, for that matter, to perform matrix multiplication of two
p × p matrices) as:
2 3 2
T (p) ⩽ (c 1 p + c 2 (p − 1)) p + c 3 = (c 1 + c 2 )p − c2 p + c3 .
Thus, the amount of time it takes to square the adjacency matrix is bounded by a cubic
function of p, the order of the graph.
Since the constants are all dependent on the machines, languages, programmers and other
factors, we simplify by saying that the problem of squaring the adjacency matrix of a graph
of order p is On, The Order of p , or O(p ) (read big oh of p ). Hence, we say that the time
3 3 3
Formally, we say that given two functions of n, g(n) = O(f (n)) if there exist constants k and
m,such that |g(n)| ⩽ k|f (n)| for all n ⩾ m. An algorithm has polynomial time complexity if its
computational time complexity T (n) = O(p(n)) for some polynomial p in the input size n. We
call any problem for which no polynomial algorithm can exist an intractable problem.
There is yet another kind of problem that at the present time sits between the polynomial
problems and the intractable problems. In order to consider such problems, we must
consider decision problems, that is, problems that can be answered "yes" or "no". For
example: Given two graphs G and G , does G contain a subgraph isomorphic to G ?
1 2 1 2
There is yet another special type of problem within N P , the so called N P -complete
problems. These problems have been shown to be in a sense the hardest problems in N P .
That is, a problem X is N P -complete if a solution for X provides a solution for all other
problems Y in N P . By this we mean that there is a polynomial algorithm to "transform" X
into Y (and,hence, to convert a solution of X into a solution of Y ).
Degree Sequences
Given any graph, we can easily find the degree of each of its vertices. Each graph can be
associated with such a unique sequence called its degree sequence. For convenience,
these degrees can be ordered to form a nonincreasing sequence of nonnegative integers.
The first question you might think of is, Can we reverse this process? By this we mean,
given a degree sequence S, can we determine a graph with S as its degree sequence?
Let's begin with the question, When is a sequence S the degree sequence of some graph?
First, degrees are nonnegative integers; thus, all the terms of the sequence must be
nonnegative integers. Next, if S has p terms, then no term can be larger than p − 1, because
no vertex can be adjacent to more than the p − 1 other vertices.
Consider the sequence S : 1, 1, 1. For S to be the degree sequence of some graph, the
graph must have exactly three vertices of degree one. But by Theorem, any graph must
have an even number of vertices of odd degree, and therefore S cannot be a degree
sequence. Remember, Theorem tells us that the sum of the degrees of the vertices in any
graph must be an even number, and hence the sum of the terms of S must be even. We see
that degree sequences do not always provide enough information to uniquely describe a
graph.
Proof:
Suppose that the sequence S is graphical and let G be a graph of order p − 1 with
1 1
new graph G with degree sequence S by inserting into G a new vertex x and the 1 1
vertices are now the remaining values of S . Thus, we have constructed a graph with
degree sequence S, and so S is graphical.
Conversely, suppose that S is graphical and among all graphs with degree sequence S,
let G be chosen with the following properties:
not adjacent to the d other vertices of largest degrees. Then there exist two vertices x
1 i
and x with d
j j > di and such that x is adjacent to x but x is not adjacent to x . Since
i 1 j 1
Now, removing the edges x x and x x and inserting x x and x x results in a new
1 i j k 1 j i k
graph H with degree sequence S . However, in H the sum of the degrees of the vertices
adjacent to x is greater than in G, which contradicts second property in our choice of G
1
. Thus, x must be adjacent in G to the d other vertices of largest degree. Now the
1 1
The fundamental step in the last proof was deleting the two edges x 1
xi and x j
xk and
inserting the edges x 1
xj and x i
xk . This operation left the degrees of the vertices unchanged
but varied the structure, and, it has come to be called an edge interchange.
We have an interesting result related to construction of a graph from its intermediate degree
sequences.
Theorem:
Any realization of a graphical sequence can be obtained from any other realization by a
finite sequence of edge interchanges.
An alternate result for testing graphical sequences is due to Erdös and Gallai.
i=1
p p
∑ d i ⩽ k(k − 1) + ∑ min{k, d i }.
i=1 i=k+1
Let's consider a similar question for digraphs. We want a sequence of ordered pairs,
where the first entry of the pair is the indegree of the vertex and the second entry is the
outdegree. A sequence S : (i 1 , o 1 ), (i 2 , o 2 ), … , (i p , o p ) is called digraphical degree
sequence of some digraph.
Theorem:
A sequence S : (i 1 , o 1 ), (i 2 , o 2 ), … , (i p , o p ) of ordered pairs of nonnegative integers with
i1 ⩾ i2 ⩾ … ⩾ ip is digraphical if and only if i k ⩽ p − 1 and o k ⩽ p − 1 for each k, and
p p p j p
for 1 ⩽ j < p.
Fundamental Counting
By ⌊x⌋ we mean the greatest integer less than or equal to x, and by ⌈x⌉ we mean the least
integer greater than or equal to x.
As an illustration of the Pigeon Hole Principle, consider the following claim: In any group of
six people, there are either three mutual acquaintances or three mutual nonacquaintances.
We can model this group of people using graphs. Represent each person as a vertex; two
vertices are joined by an edge if and only if the corresponding people are acquaintances.
What graph theoretic property will allow us to verify the claim? Three mutual acquaintances
–
would induce a
K3 K3 in the graph, while three mutual nonacquaintances would induce a .
Thus, we can restate the claim as follows.
Theorem:
–
K3 K3Any graph on six vertices contains an induced or an induced as a subgraph.
Another example of a fundamental counting technique occurs when we are trying to count
the number of available choices we have in performing some graph operation. For example,
suppose we want to determine the number, num(p, G), of graphs on a set of p vertices (that
is, labeled graphs).
Theorem:
If N =
p
( ),
2
then there are 2 labeled graphs on p vertices.
N
Miscellaneous:
Theorem:
G1 × G2 is isomorphic to G 2 × G1 .
To prove this theorem, we will leverage the commutative property of cartesian products
in set theory: For any two sets A and B, the Cartesian product of these sets satisfies:
A × B = B × A.
theory:
V (G 1 × G 2 ) = V 1 × V 2 = V 2 × V 1 = V (G 2 × G 1 ).
If u 1
= u2 and (v 1
, v 2 ) ∈ E(G 2 ), then ϕ((u 1
, v 1 )) = (v 1 , u 1 ) and ϕ((u 2
, v 2 )) = (v 2 , u 2 )
are adjacent in G 2
× G1 because v 1
= v2 and (u 1
, u 2 ) ∈ E(G 1 ) .
If v = v and (u , u ) ∈ E(G ), then ϕ((u , v )) = (v , u ) and ϕ((u
1 2 1 2 1 1 1 1 1 2, v 2 )) = (v 2 , u 2 )