An undirected graph(adirected graph) (Fig.9.3)Gis a pair offinite sets (V, E) such thatEis a binary symmetric relation on V. The set of vertices (or nodes) is denoted byV(G) and the set of edges is denoted byE(G).
Adirected graph (Fig. 9.4) is a pair offinite sets (V, E) whereE is a binary relation (that may not be symmetric) on V. A directed acyclic graph (dag) is a directed graph that has no cycles. The example below is of a directed graph with three edges and four vertices.
An edge e2E consists of a pair 〈x,y〉 where x, y are adjacent nodes in the graph. The degreeof xis the number of nodes that are adjacent to x. The set of edges is denoted byE(G), and the set of vertices is denoted by V(G).
Aweighted graphis a graphG= (V,E) together with a weighting functionw:E
!ℕ,whichassociates a weight with every edge in the graph. A weighting function may be employed in modelling computer networks: for example, the weight of an edge may be applied to model the bandwidth of a telecommunications link between two nodes. Another application of the weighting function is in determining the distance (or shortest path) between two nodes in the graph (where such a path exists).
a
b
c d
•
•
•
• Fig. 9.3 Undirected graph
p
• • •
• r s
q
Fig. 9.4 Directed graph
For an adirected graph the weight of the edge is the same in both directions: i.e.
w(vi,vj) = w(vj,vi) for all edges〈vi,vj〉in the graphG, whereas the weights may be different for a directed graph.
Two verticesx,yare adjacent ifxy2E, andxandyare said to be incident to the edgexy. A matrix may be employed to represent the adjacency relationship.
Example 9.1
a
b
c d
•
• •
• u
• g
v x
f •
y
w
• e
Consider the graph G= (V, E) where E= {u= ab, v=cd, w= fg, x= bg, y= af}
An adjacency matrix (Fig.9.5) may be employed to represent the relationship of adjacency in the graph. Its construction involves listing the vertices in the rows and columns, and an entry of 1 is made in the table if the two vertices are adjacent and 0 otherwise.
Similarly, we can construct a table describing the incidence of edges and vertices by constructing an incidence matrix (Fig.9.6). This matrix lists the vertices and edges in the rows and columns, and an entry of 1 is made if the vertex is one of the nodes of the edge and 0 otherwise.
g f e d c b a
g f e d c b a
0 1 0 0 0 1 0
1 0 0 0 0 0 1
0 0 0 0 0 0 0
0 0 0 0 1 0 0
0 0 0 1 0 0 0
1 0 0 0 0 0 1
0 1 0 0 0 1 0
g f e d c b a
0 1 0 0 0 1 0
1 0 0 0 0 0 1
0 0 0 0 0 0 0
0 0 0 0 1 0 0
0 0 0 1 0 0 0
1 0 0 0 0 0 1
0 1 0 0 0 1 0
g f e d c b Fig. 9.5 Adjacency matrix a
g f e d c b a
0 1 1 0 0
1 0 1 0 0
0 0 0 0 0
0 0 0 1 0
0 0 0 1 0
0 1 0 0 1
1 0 0 0 1
y x w v u
0 1 1 0 0
1 0 1 0 0
0 0 0 0 0
0 0 0 1 0
0 0 0 1 0
0 1 0 0 1
1 0 0 0 1
y x w v Fig. 9.6 Incidence matrix u
144 9 Graph Theory
Two graphsG= (V, E) andG′= (V′,E′) are said to be isomorphic if there exists a bijectionf:V!V′such that for anyu,v2V,uv2E,f(u)f(v)2E′. The mapping fis called an isomorphism. Two graphs that are isomorphic are essentially equiv- alent apart from a re-labelling of the nodes and edges.
LetG= (V,E) andG′= (V′,E′) be two graphs then G′is a subgraphof Gif V′VandE′E. GivenG= (V, E) andV′Vthen we can induce a subgraph G′= (V′, E′) by restricting GtoV′ (denoted byG |V′|). The set of edges in E′ is defined as:
E0¼ fe2E:e¼uvandu;v2V0g
The degree of a vertex v is the number of distinct edges incident to v. It is denoted by degvwhere
degv¼ jfe2E:e¼vxfor somex2Vgj
¼ jfx2V:vx2Egj A vertex of degree 0 is called an isolated vertex.
Theorem 9.1 Let G = (V,E) be a graph then X
v2Vdegv¼2j jE
Proof This result is clear since each edge contributes one to each of the vertex degrees. The formal proof is by induction based on the number of edges in the graph, and the basis case is for a graph with no edges (i.e. where every vertex is isolated), and the result is immediate for this case.
The inductive step (strong induction) is to assume that the result is true for all graphs withkor fewer edges. We then consider a graphG= (V, E) withk+ 1 edges.
Choose an edge e= xy 2 E and consider the graph G′= (V, E′) where E′=E\{e}. ThenG′is a graph withkedges and therefore letting deg′vrepresents the degree of a vertex inG′ we have:
X
v2V
deg0v¼2j j ¼E0 2ðj j E 1Þ ¼2j j E 2
The degree ofxand yare one less inG′than they are inG. That is, X
v2V
degv2¼X
v2V
deg0v¼2j j E 2 )X
v2V
degv¼2j jE
A graph G= (V,E) is said to becomplete if all the vertices are adjacent: i.e.
E=VV. A graphG= (V,E) is said to besimple graph if each edge connects two different vertices, and no two edges connect the same pair of vertices. Simi- larly, a graph that may have multiple edges between two vertices is termed a multigraph.
A common problem encountered in graph theory is determining whether or not there is a route from one vertex to another. Often, once a route has been identified the problem then becomes that offinding the shortest or most efficient route to the destination vertex. A graph is said to beconnectedif for any two given verticesv1, v2inVthere is a path from v1tov2.
Consider a person walking in a forest from A to B where the person does not know the way to B. Often, the route taken will involve the person wandering around aimlessly, and often retracing parts of the route until eventually the desti- nation B is reached. This is an example of awalkfromv1tovkwhere there may be repetition of edges.
If all of the edges of a walk are distinct then it is called atrail. Apath v1,v2,…, vkfrom vertexv1tovkis of lengthk− 1 and consists of the sequence of edges〈v1, v2〉,〈v2,v3〉,…,〈vk−1,vk〉where each〈vi,vi+1〉is an edge inE. The vertices in the path are all distinct apart from possiblyv1andvk.. The path is said to be a cycle if v1=vk.. A graph is said to beacyclicif it contains no cycles.
Theorem 9.2 Let G = (V,E) be a graph and W = v1,v2,…,vkbe a walk from v1 to,vk. Then there is a path from v1to,vkusing only edges of W.
Proof The walkWmay be reduced to a path by successively replacing redundant parts in the walk of the form vi vi+1 …, vj where vi= vj with vi. That is, we successively remove cycles from the walk and this clearly leads to a path (not necessarily the shortest path) fromv1to,vk.
Theorem 9.3 Let G = (V,E) be a graph and let u,v2V with u6¼v. Suppose that there exists two different paths from u to v in G,then G contains a cycle.
v1= w1= u•
•
•
•
• Q •
P •
•
•
vk= wk
P
Q
vn= wm= v
wk+1 vk+1
vi= wj
wj-1
vi-1 vi+1
wj+1
Suppose that P=v1, v2,…, vn and Q=w1,w2,…, wmare two distinct paths fromutov(whereu 6¼v), andu= v1=w1andv=vn= wm. SupposePandQare identical for thefirstkvertices (kcould be 1), and then differ (i.e.,vk+16¼wk+1).
ThenQcrossesPagain atvn= wm, and possibly several times before then. Suppose
146 9 Graph Theory
thefirst occurrence is atvi=wjwithk<i n. Thenwk,wk+1,wk+2,…,wjvi−1, vi−2,…,vkis a closed path (i.e. a cycle) since the vertices are all distinct.
If there is a path fromv1tov2then it is possible to define thedistancebetweenv1 andv2. This is defined to be the total length (number of edges) of the shortest path betweenv1and v2.
9.2.1 Hamiltonian Paths
AHamiltonian path3in a graphG= (V,E) is a path that visits every vertex once and once only. In other words, the length of a Hamiltonian path is |V|−1. A graph is Hamiltonian-connected if for every pair of vertices there is a Hamiltonian path between the two vertices.
Hamiltonian paths are applicable to the travelling salesman problem, where a salesman4wishes to travel tokcities in the country without visiting any city more than once. In principle, this problem may be solved by looking at all of the possible routes between the various cities, and choosing the route with the minimal distance.
For example, Fig.9.7showsfive cities and the connections (including distance) between them. Then, a travelling salesman starting at A would visit the cities in the order AEDCBA (or in reverse order ABCDEA) covering a total distance of 14.
However, the problem becomes much more difficult to solve as the number of cities increase, and there is no general algorithm for its solution. For example, for the case of ten cities, the total number of possible routes is given by 9! = 362,880, and an exhaustive search by a computer is feasible and the solution may be determined quite quickly. However, for 20 cities, the total number of routes is given by 19! = 1.21017, and in this case it is no longer feasible to do an exhaustive search by a computer.
There are several sufficient conditions for the existence of a Hamiltonian path, and Theorem9.4 describes a condition that is sufficient for the existence of a Hamiltonian path.
A B
C D E 3 4
3 2
2
6 2
7 5 4
Fig. 9.7 Travelling salesman problem
3These are named after Sir William Rowan Hamilton, a nineteenth century Irish mathematician and astronomer, who is famous for discovering quaternions [1].
4We use the term“salesman”to stand for“salesman”or“saleswoman”.
Theorem 9.4 Let G = (V,E) be a graph with |V| = n and such that deg v + deg w n −1 for all non-adjacent vertices v and w. Then G possesses a Hamiltonian path.
Proof The first part of the proof involves showing that G is connected, and the second part involves considering the largest path inGof lengthk− 1 and assuming thatk< n. A contradiction is then derived and it is deduced that k= n.
We assume thatG′= (V′,E′) andG′′= (V′′,E′′) are two connected components ofG, then |V′| + |V′′| nand so ifv2V′andw2V′′thenn−1 degv+ deg w |V′|− 1 + |V′′|− 1 = |V′| + |V′′|−2 n −2 which is a contradiction, and soGmust be connected.
LetP=v1, v2,…,vkbe the largest path in Gand suppose k< n. From this a contradiction is derived, and the details for are in [2].