DMGT Unit5
DMGT Unit5
GRAPH THEORY - II
Planar and non-planar graphs:
A graph which can be represented by at least one plane drawing in which the edges meet
only at the vertices is called a planar graph. A graph which cannot be represented by a
plane drawing in which the edges meet only at the vertices is called a non-planar graph.
Problem: Show that (i) a graph of order 5 and size 8 and (ii) a graph of order 6 and size 12
are planar.
Solution: A graph of order 5 and size 8 can be represented by a plane drawing in which
the edges of the graph meet only at the vertices, as shown below. Similarly, shows that a
graph of order 6 and size 12 is planar.
Problem: show that the complete graph K5 (namely, the kuratowski’s first graph) is a non-
planar graph.A
Solution: We first recall that in the complete graph K5 there are 5 vertices and there is an
edge between every pair of vertices, totaling to 10 edges; as shown the figure. This figure
is shown below with the vertices named as v1,v2 ,v3 ,v4 , and v5 and the edges named as
e1, e2 , e3 ,e4 ,........ e10 .
v1
e4 e2 e1
v5 e7 v2
e3 e6
e10 e9 e5
v4 v3
e8
In the above drawing of K5, the five edges e1,e5 ,e8 ,e10 , v4 from pentagonal cycle
and the remaining five edges e2 ,e3 ,e6 ,e7 ,v9 are all inside this cycle and intersect at points
other than the vertices.
Let us try to draw a diagram of K5 in which no two of its edges intersect. The pentagonal
cycle present in the above figure does not contain any mutually intersecting edges. Let us
start our (new) drawing of K5 with this cycle; the cycle is shown in figure (a).
Consider the edge e7 v1, v5. This edge can be drawn either inside or outside
the pentagonal cycle. Suppose we draw it inside, as shown in figure (b) - the other case is
similar. Now, consider the edges e2 v1, v3 and e3 v1, v4. If we draw these edges also
inside the pentagon, they will intersect e7 ; therefore, let us draw both of them outside; see
in figure (b).
v1
e4 e1 v1
e4 e1
v5 v2 e7
v5 v2 e2
e10 e5 e3 e6 e5
e10
v4 e8 v3
v4 e8 v3
(b)
(a)
Next, consider the edge e6 v2 ,v4 . If we draw this edge outside the pentagon, it intersects
the edge e2 see+ figure (b). Therefore, let us draw e6 inside the pentagon.
Lastly, consider the edge e9 v3 , v5 . If we draw this edge outside the pentagon, it
intersects the edge e3 , and if we draw it inside, it crosses the edge e6 .
This demonstrates that in every possible plane drawing of K5 at least two edges of
K5intersect at a point which is not a vertex of K5. This proves that K5 is a non-planar
graph.
Problem: Show that the complete bipartite graph K3,3 (namely, the Kuratowski’s second
graph) is non-planar.
Solution: By definition, K3,3 is the graph with 6 vertices and 9 edges, in which the vertex
set is made up of two bipartites V1 andV2 each containing three vertices such that every
vertex in V1 is joined to every vertex inV2 by an edge and vice-versa.
Let us name the vertices in V1 as v1,v2 , v3 and the vertices in V2 as v4, v5, v6. Also let
the edges be named as e1,e2 ,e3 ,............,e9 .A diagram of the graph is shown in figure. In this
diagram of K3,3 , the six edges
e1 v1, v4, e4 v4, v2, e5 v2, v5, e8 v5,v3,e9 v3,v6, and e3 v6,v1 from a
hexagonal cycle and the remaining three edges e2 ,e6 ,e7 intersect with these edges and/or
among themselves at points other than the vertices.
v1 e1 v4
e3 e2 e4
v2 e5 v5
e6
e7 e8
v3 v6
V1 e9 V2
Let us try to draw a diagram of K3,3 in which no two of its edges intersect. The hexagonal
cycle present in above figure does not contain any mutually intersecting edges. Let us start
our drawing of K3,3 with this cycle. This cycle is exhibited separately in figure (a).
v1 e1 v4 v1 e1 v4
e4
e3 e4 e3 e6
v6 v2 v6 v2 e2
e9 e5
e9 e5
v3 e8 v5 v3 e8 v5
(a) (b)
Consider the edge e6 = {v2, v6}. This edge can be drawn either inside the
hexagonal cycle or outside it. Let us draw it inside as shown in figure (b) - the other case
is similar. Now, consider the edge e2 = {v1, v5}. If we draw this edge inside the hexagon, it
intersects the edge e6. Therefore, let us draw it outside the hexagon see figure (b).
Next, consider the edge e7 = {v3, v4}. If this edge is drawn inside the hexagon,
it intersects the edge e6, and it if is drawn outside the hexagon, it crosses the edge e2.
This demonstrates that in every possible plane drawing of K3,3 at least two
edges of K3,3 intersect at a point which is not a vertex of K3,3. This proves that K3, 3 is a
non-planar graph.
Euler’s Formula: If G is planar graph, then G can be represented by a diagram in a plane
in which the edges meet only at the vertices. Such a diagram divides the plane into a
number of parts, called regions of which exactly one part is unbounded. The number of
edges that form the boundary of a region is called the degree of that region.
For example, in the diagram of a planar graph shown below, the diagram
divides the plane into 6 regions R1, R2, R3, R4, R5, R6. We observe that each of the regions
R1 to R5 is bounded and the region R6 is unbounded. That is R1 to R5 are in the interior of
the graph while R6 is in the exterior.
R2 R6
R1 R3
R5
R4
We further observe that, in the above figure the boundary of the region R1 is made up of
two edges. Therefore, the degree of R1 is 2; we write this as d(R1) = 2. The boundary of
each of the regions R2 and R4 is made up of 3 edges; therefore, d(R2) = d(R4) = 3. The
boundary of the region R3 consists of 4 edges of which one is a pendant edge. Therefore,
d(R3) =5. The region R5 is bounded by a single edge (loop); therefore, d(R5) = 1. The
boundary of the exterior region R6 consists of six edges; d(R6) = 6. We note that
d(R1)+d(R2)+d(R3)+d(R4)+d(R5)+d(R6) = 20 which is twice the number of
edges in the graph. This property is analogous to the handshaking property and is true for
all planar graphs.
Note: Euler formula: A connected planar graph G with n vertices and m edges has
exactly m – n +2=r (regions) in all of its diagrams i.e r-m+n=2.
Problem: Verify Euler’s formula for the planar graph shown in below
R2 R6
R1 R3
R5
R4
Solution: The given graph has n = 6 vertices, m = 10 edges and r = 6 regions. Thus
n – m+r = 6 – 10+6 = 2
The Euler’s formula is thus verified for the given graph.
Problem: Verify Euler’s formula for the planar graphs shown below
Solution:
(a) (b)
We observe that the first of the given graphs has n = 17 vertices, m = 34 edges and
r = 19 regions. Thus, n – m+r = 17 – 34+19 = 2.
In the second of the given graphs, there are = 10 vertices, m = 24 edges and r = 16
regions, so that n – m+r = 10 – 24 +16 = 2.
Thus, for both of the given graphs, Euler’s formula is verified.
Graph Coloring: Given a planar or non-planar graph G, if we assign colors to its vertices
in such a way that no two adjacent vertices have the same color, then we say that the
graph G is properly colored. In other words, proper coloring of a graph means assigning
colors to its vertices such that adjacent vertices have different colors.
In the above figure, the first two graphs are properly colored whereas the third graph is not
properly colored.
By examining the first two graphs in the above which are properly colored, we note the
following:
(1) A graph can have more than one proper coloring.
(2) Two non-adjacent vertices in a properly colored graph can have the same
color.
Chromatic number: A graph G is said to be k-colorable if we can properly color it with
k(number of ) colors. A graph G which is k-colorable but not (k – 1) colorable is called a
k-chromatic graph.
If a graph G is k-chromatic, then k is called the chromatic number of G. The
chromatic number of a graph is the minimum number of colors with which the graph can
be properly colored. The chromatic number of graph G is usually denoted by χ(G).
Some Results: The following results are direct consequences of the definition of the
chromatic number.
(1) A graph consisting of only isolated vertices (i.e. Null graph) is 1-chromatic.
(Because no two vertices of such a graph are adjacent and therefore we can assign
the same color to all vertices)
(2) A graph with one or more edges is at least 2-chromatic. (Because, such a graph
has at least one pair of adjacent vertices which should have different colors).
(3) If a graph G contains a graph G1 as a subgraph, then χ(G) ≥ χ(G1).
(4) If G is a graph of n vertices, then χ(G) ≤ n.
(5) χ(Kn) = n for all n≥1. (Because, in Kn, every two vertices are adjacent, and as
such all the n vertices should have different colors).
(6) If a graph G contains Kn as a subgraph, then χ(G) ≥ n.
Problem: Find the chromatic number of each of the following graphs.
v5 v4 v2 v1 v8
v1 v3 v6 v2
v6 v3 v5
v4 v5 v3
v1 v2 v4
(a) (b) (c)
Solution:
(i) For the graph (a), let us assign a color α to the v1. Then, for a proper coloring, we
have to assign a different color to its neighbor’s v2, v4, v6. Since v2, v4, v6 are mutually
nonadjacent vertices, they can have the same color, say β (which is different from α).
Since v3, v5 are not adjacent to v1, these can have the same color as v1, namely α.
Thus, the graph can be property colored with at least two colors, with the vertices v1, v3, v5
having one color α, and v2, v4, v6 having a different color β. Hence, the chromatic
number of the graph is 2.
(ii) For the graph (b), let us assign the color α to the vertex v1. Then, for a proper
coloring, its neighbor’s v2, v3 and v4 cannot have the color α, but v5 can have the color
α. Furthermore, v2, v3, v4 must have different colors, say β, γ, δ. Thus, at least four
colors are required for a proper coloring of the graph. Hence the chromatic number of
the graph is 4.
(iii) For the graph (c), we can assign the same color; say α, to the non-adjacent
vertices v1, v3, v5. Then the vertices v2, v4, v6 can be assigned the same color other than
α. Suppose we assign a color, β to v2, v4, v6. Consequently v7 and v8 can be assigned
the
same color which is different from both α and β. Thus, a minimum of three colors are
needed for a proper coloring of the graph. Hence its chromatic number is 3.
Problem: Find the chromatic numbers of the following graphs.
v1
v1
v2 v10 v7 v8
v9 v6 v5
v2 v6 v11 v5 v4
v8 v7 v10 v9
v3 v4 v3
(a) (b)
Solution:
(i) We note that the graph (a) is the Petersen graph. By observing the graph, we note that
the vertices v1, v3, v6 and v7 can be assigned the same color, say α. Then the vertices
v2, v4, v8 and v10 can be assigned the same color, β (other than α). Now, the vertices v5
and v9 have to be assigned colors other than α and β; they can have the same color γ.
Thus, a minimum of three colors are required for a proper coloring of this graph.
Hence, the chromatic number of this graph is 3.
(ii) By observing the graph (b), we note that the vertices v1, v3, v5 and v11 can be assigned
the same color α and all the remaining vertices: v2, v4, v7, v8, v9 and v10 can be
assigned the same color β (other than α). Thus, two colors are sufficient for proper
coloring of the graph. Hence, its chromatic number is 2.
Trees and their basic properties:
A graph G is called a tree if it is connected and has no cycles.
It immediately follows that a tree has to be a simple graph; because loops and
parallel edges form cycles.
The graphs shown below are all trees. We observe that each of these trees
possesses at least two pendant vertices. A pendant vertex of a tree is also called a leaf.
(a) (b)
A graph which is a tree is usually denoted by T (instead of G) to emphasize the structure.
Note:
(1) In a tree, there is one and only one path between every pair of vertices.
(2) If in a graph G there is one and only one path between every pair of vertices,then
G is a tree.
(3) A tree with n vertices has (n – 1) edges.
(4) A connected graph G is a tree if and only if adding an edge between any two
vertices in G creates exactly one cycle in G.
Minimally connected graph: A connected graph is said to be minimally connected if the
removal of any one edge from it disconnects the graph. The below graph is minimally
connected graph.
(a) (b)
In a rooted tree, we denote the root by r and draw the (diagram of the) tree
downward from an upper level to a lower level, so that the arrows can be dropped. Then
the root r will be at the uppermost level and all other vertices will be at lower levels.
A vertex v of a rooted tree is said to be at the kth level or has level number k if
the path from r to v is of length k. If v1 and v2 are two vertices such that v1 has lower level
number than v2 and there is a path from v1 to v2, then we say that v1 is an ancestor of v2,
or that v2 is a descendant of v1. In particular, if v1 and v2 are such that v1 has a lower level
number than v2 and there is an edge from v1 to v2, then v1 is called the parent of v2 or v2 is
called the child of v1. Two vertices with a common parent are referred to as siblings. A
vertex whose out-degree is 0 is called a leaf. A vertex which is not a leaf is called an
internal vertex.
For example, suppose we redraw the directed tree of above figure (b) as shown below
without arrows and with vertices labeled.
r
v1 v2
v3 v4
v5 v6 v7
v8 v9
In this rooted tree, we note that
(1) v1 and v2 are at the first level, v3, v4 are at the second level, v5, v6, v7 are at the third
level, and v8 and v9 are at the fourth level.
(2) v1 is the ancestor of v3, v5, v6 ( or v3, v5, v6 are the descendants of v1), and v2 is the
ancestor of v4, v7, v8, v9 (or v4, v7, v8, v9 are the descendants of v2).
(3) v1 is the parent of v3 (or v3 is a child of v1).
(4) v5 and v6 are siblings, and v8 and v9 are siblings.
(5) v5, v6, v8, v9 are leaves, and all other vertices are internal vertices.
Binary tree: A rooted tree T is called a binary rooted tree, or just a binary tree if every internal
vertex of T is of out-degree 1 or 2; that is if every vertex has at most two children.
A rooted tree T is called a complete binary tree if every internal vertex of T is of out-degree 2;
that is if every internal vertex has two children.
The rooted tree shown in figure (a) is a binary tree; it is not a complete binary tree.
The rooted tree shown figure (b) is a complete binary tree.
r
v1 v2
v3 v4
v5 v6 v7
v8 v9
(a) (b)
Balanced tree: If T is a rooted tree and h is the largest level number achieved by a leaf of T, then
T is said to have height h. A rooted tree of height h is said to be balanced if the level number of
every leaf if h or (h – 1).
The tree shown in figure (a) is of height 4 and is balanced too. The tree shown in
above figure is of height 4 but is not balanced.
r
v1 v2
v3 v4
v5 v6 v7
v8 v9
(a) (b)
Full binary tree: Let T be a complete binary tree of height h. Then T is called a full
binary tree if all the leaves in T are at level h.
The complete binary tree shown in figure (b) is not a fully binary tree. The tree
shown in figure (a) is a fully binary tree.
(a) (b)
Spanning Trees: Let G be a connected graph. A subgraph T of G is called a spanning tree of
G if (i) T is a tree, and (ii) T contains all vertices of G.
Since a spanning tree T of a graph G is a subgraph of G that contains all vertices
of G, T is a maximal subgraph of G. A spanning tree is also called a maximal tree. The names
skeleton and scaffolding are also used for a spanning tree. The edges of a spanning tree are
called its branches.
If T is a spanning tree of a graph G, then the edges of G that are not in T are
called the chords of G with respect to T. The set of all chords of G is the complement of T in
G. This set is called the chord-set or cotree of T in G and denoted by T . Evidently G T T .
For the graph in below (a) and (b) are spanning trees and the graph (c) is the corresponding
chord-set.
v1
v1 v1
v2 v3
v2 v3 v2 v3
v4 v5
v4 v5 v4 v5
(a): G (b): T (c): T
In a disconnected graph of n vertices we cannot find a spanning tree with n
vertices. But each component of a disconnected graph can have a spanning tree. These
spanning trees together form a spanning forest.
Problem: Find all the spanning trees of the graph shown below;
v1
v2 v4
v3
Solution: A spanning tree of the given graph must be a subgraph which is a tree and which must
contain all the vertices of the graph. Since there are four vertices and five edges in the given
graph, its spanning tree must have four vertices and three edges. Each such tree is got by deleting
two edges from the graph. There are eight such trees; they are shown below.
v3
v4 v6 v7
v5
v8
First we assign the first vertex v1 to the variable v and initialize T as just the
vertex v1. Going to Step2, we find that the vertex v2 is the first vertex w such that {v1,
w}€E and w has not been visited earlier. So, we attach the edge {v1, v2} to T, assign v2 to
v and return the Step2.
At v = v2 we find that the first adjacent vertex that provides an edge for T is v7.
Consequently, the edge {v2, v7} is attached to T, v7 is assigned to v, and we again return to
Step2.
At v = v7 we find that the first adjacent vertex that provides and edge for T is
v3. Consequently, the edge {v7, v3} is attached to T, v1 is assigned to v and we return to
Step2.
Now, we note that there is no new vertex which we can obtain from v3,
because the adjacent vertex v1 has already been visited. So we go to Step3. Since v = v3
and v3 is not the first vertex, we go to Step4. Now, we back track from v3 and assign the
vertex v7 to v, and then we return to Step2. At this time we see that the edge {v7, v5} can
be added to T.
Continuing the process, we attach the edges {v1, v4}, {v4, v8} and finally
{v8, v6} to T.
Thus, a spanning tree that consists of the edges {v1, v2},{v2, v7}, {v7, v3},
{v7, v5}, {v1, v4}, {v4, v8}, {v8, v6} has been determined. This depth-first search spanning
tree is shown below
v1 v2
v3
v6
v4 v7
v5
v8
As another illustration, we indicate that for the graph shown below the depth-first search
spanning tree consists of the edges {a, b}, {b, d}, {b, e}, {e, f}, {e, h}, {a, c}, {c, g},
{g, i} and {g, j}. This spanning tree is shown below.
a b a b
c d e f Answer c d e f
g h g h
j i j i
BFS Algorithm:
Let G = (V, E) be a connected graph of order n, with vertices labeled v1,
v2,….,vn in some specified order. We refer to an ordered list Q of vertices of G as a queue
in G. vertices are inserted into this list at one end and deleted from the list at the other end.
The first vertex inserted in the queue is the first vertex that can be taken out of it. The BFS
algorithm specifies the following steps for determining a spanning tree T of G, wherein v
is a variable to which a vertex of G is assigned.
Step1: Assign the first vertex v1 and insert this vertex in the queue Q and initialize T as
the tree made up of this one vertex v1. (This vertex will turn out to be the root of the
spanning tree T that develops).
Step2: Delete v from the front of Q. When v is deleted, consider vk for each 2≤k≤n. If the
edge {v, vk}€E and vk has not been visited previously, attach this edge to T. If we examine
all of the vertices previously visited and obtain no new edge, the tree T is the desired
spanning tree.
Step3: Insert the vertices adjacent to each v at the rear of the queue Q, according to the
order in which they are visited. Then return to Step2.
The spanning tree of G determined by using the above steps is called the
breadth-first search spanning tree for G for the given order of vertices of G.
Example:
v1 v2
v3
v4 v6 v7
v5
v8
Start with vertex v1. Insert v1 in Q and initialize T as this vertex (which will
turn out to be the root of the resulting tree T).
In Step2, we delete v1 from Q and visit the vertices adjacent to it, namely v2,
v3, v4, v6. This results in our attaching to T the edges {v1, v2}, {v1, v3}, {v1, v4}, {v1, v6}.
Continuing to Step3, we insert v2, v3, v4, v6 (in the order) in Q and return to Step2. Now
v2, v3, v4, v6 are deleted from Q, and the vertices adjacent to them are visited. This results
in the vertices v7, v8 and the edges {v2, v7} and {v4, v8} which are attached to T.
Next, we go to Step3 and insert v7, v8 in Q. Returning to Step2, we delete each
of these vertices from Q and visit the vertex v5 which is adjacent to v7 and which is
preciously unvisited, and attach the edge {v7, v5} to T. The vertex v8 has no previously
unvisited adjacent vertex.
At this stage, all the vertices of G have been visited, and we stop the process.
Thus, a spanning tree that consists of the edges {v1, v2}, {v1, v3}, {v1, v4},
{v1, v6}, {v2, v7}, {v4, v8}, {v7, v5} has been determined. This breadth-first search
spanning tree is shown below.
v1 v2
v3
v6
v4 v7
v5
v8
We observe that this spanning tree is not the same as the spanning tree
obtained in DFS Algorithm. Thus, for a given graph, the depth-first search and thebreadth-
first search spanning trees are not necessarily identical.
As another illustration, we indicate that for the graph shown below.wherein the
order of vertices is alphabetic the breadth-first search spanning tree consists of the edges
{a, b}, {a, c}, {a, d}, {b, e}, {c, g}, {e, f}, {e, h}, {g, i} and {g, j}. This spanning tree is
shown below.
a b a b
c d e f Answer c d e f
g h g h
j i j i
Observe that this tree is not identical with the depth-first search spanning tree shown in
Minimal Spanning Tree: Let G be a graph and suppose there is a positive real number
associated with each edge of G. Then G is called a weighted graph and the positive real
number associated with an edge e is called the weight of the edge e.
We consider all spanning trees of a weighted, connected graph, and find the
weights of every one of these spanning trees. A spanning tree whose weight is the least is
called a minimal spanning tree of the graph. This tree is not unique.
Example: Consider the connected weighted graph shown below. The numbers shown
adjacent to the edges are their weights.
1 5 3 4
2
1 5 3 4 1 3 4 1 5 4
2 2
(a) (b) (c)
We observe that the weights of these three spanning trees are 16, 13 and 15 respectively.
Of these trees, the second one has the minimum weight. This is spanning tree for the graph
shown above.
Algorithms for Minimal Spanning Tree: There are several methods of constructing
minimal spanning trees. Below we give the working rules (algorithms) of two of such
methods. The first of these is due to kruskal and the second is due to Prim.
Kruskal’s Algorithm:
The working rule for the kruskal’s method may stated as follows:
Step1: Given a connected, weighted graph G with n vertices, list the edges of G in the
order of non-decreasing weights.
Step2: Starting with a smallest weighted edge, proceed sequentially by selecting one edge
at a time such that no cycle is formed.
Step3: Stop the process of Step2 when (n – 1) edges are selected. These n – 1
edges constitute a minimal spanning tree of G.
Example: Using the kruskal’s algorithm, find a minimal spanning tree of the weighted
graph shown below:
B C
8
6 7 3
A 5 5 R
6 10 3
P Q
Solution: We observe that the given graph has 6 vertices; hence a spanning tree thereof
will have 5 edges. Let us put the edges of the graph in the non-decreasing order of their
weights and successively select 5 edges in such a way that no cycle is created. This
scheme is summarized in the following table:
Edge CR QR BP CQ AB AP CP AC BQ
Weight 3 3 5 5 6 6 7 8 10
Select Yes Yes Yes No Yes No Yes
Observe that CQ is not selected because CR and QR have already been
selected and the selection of CQ would have created a cycle. Further, AP is not selected
because it would have created a cycle along with BP and AB which have already been
selected. We have stopped the process when exactly 5 edges are selected.
Thus, a minimal spanning tree of the given graph contains the five edges CR,
QR, BP, AB, CP. This tree is shown below:
B C
6 3
A R
5 7 3
Example: Using Kruskal’s algorithm, find a minimal spanning tree for the weighted
graph shown below:
A 10 B
8 10
11
Q 9 C
12 7 5
P R
7
Solution: The given graph has 6 vertices and therefore a spanning tree thereof will have
5 edges. Let us put the edges of the graph in the non-decreasing order of their weights and
go on selecting 5 edges one by one in such a way that no cycle is created. The scheme is
summarized in the following table:
Edge CR PR QR BQ BR AB BC AQ PQ
Weight 5 7 7 8 9 10 10 11 12
Select Yes Yes Yes Yes No Yes
Thus, a minimal spanning tree of the given graph contains the five edges CR, PR, QR,
BQ, AB. The tree is shown below. The weight of the tree is 37.
A 10 B
8
C
7 5
P 7 R
Determine a railway network of minimal cost that connects all these cities.
Solution: Let us first prepare a graph whose vertices represent the cities, edges represent
the possible tracks and weights represent the cost. The graph is as shown below;
A minimal spanning tree of this graph represents the required network.
A 155 B
Since the graph has 8 vertices, there should be 7 edges in its minimal spanning tree. Let us
put the edges of the graph in the non-decreasing order of their weights and select seven
edges one by one in such a way that no cycle is created. The scheme is summarized in the
following table
Edge CE DF AG FG AD BC CD EF FH AB GH
Weight 95 100 120 140 145 145 150 150 150 155 160
Select Yes Yes Yes Yes No Yes Yes No Yes
Thus, a minimal spanning tree of the given graph consists of the branches CE, DF, AG,
FG, BC, CD, FH. This tree represents the required railway network. The network is shown
below:
A B
120 145
G D C
140 100 95
H 150 F E
v2 3 v3
6 2
4 1 6
v1 5 v5 7 v4
Solution: We observe that the graph has 5 vertices. Therefore, a minimal spanning tree
thereof will have 4 edges.
Let us tabulate the weights of the edges between every pair of vertices as shown below:
v1 v2 v3 v4 v5
v1 - 4 5
v2 4 - 3 6 1
v3 3 - 6 2
v4 6 6 - 7
v5 5 1 2 7 -
Now, let us start with the first row and pick the smallest entry therein. This is 4
which correspond to the edge {v1, v2}. By examining all the entries in v1 and v2- rows, we
find that the vertex other than v1 and v2 which corresponds to the smallest entry is v5 (the
smallest entry being 1). Thus, v5 is closest to the edge {v1, v2}. Let us connect v5 to the
edge {v1, v2} at v2 (because {v5, v2} has smaller weight than {v5, v1}).
Let us now examine the v5-row and note that the smallest entry is 1 which
corresponds to the edge {v5, v2}. By examining all entries in v2 and v5- rows, we find that
the vertex other than v2 and v5 which corresponds to the smallest entry is v3. Thus, v3 is
closest to the edge {v2, v5}. Let us connect v3 to the edge {v2, v5} at v5.
Thus, the edges {v1, v2}, {v2, v5}, {v5, v3} belong to a minimal spanning tree.
The vertex left over at this stage is v4 which is joined to v2, v3 and v5 in the given graph.
Among the edges that contain v4, the edges {v2, v4} and {v3, v4} have equal minimum
weights. Therefore, we can include either of these edges in the minimal spanning tree.
Accordingly, the edges {v1, v2}, {v2, v5}, {v5, v3} together with the edge
{v2, v4} or the edge {v3, v4} constitute a minimal spanning tree. Thus, for the given graph,
there are two minimal spanning trees as below:
v2 v3
v2 v3
4 6 6
2 4 1 2
1
v1 v5 v4 v1 v5 v4
(a) (b)
Problem: using Prim’s algorithm, find a minimal spanning tree for the weighted graph
shown below
A
3 1
1 4
F 3 B
3 4 2
C
E 5
4 2
D
Solution: The given graph has 6 vertices. Therefore, a minimal spanning tree thereof has
5 edges. We first prepare the following table of weights of edges:
A B C D E F
A - 1 4 1 3 3
B 1 - 2 4
C 4 2 - 2
D 1 2 - 4 5
E 3 4 4 - 3
F 3 5 3 -
Now, we examine the A-row and pick the smallest entry 1 which corresponds
to two edges {A, B} and {A, D}. Let us choose the first of these, namely, {A, B}. By
examining the A- and B-rows, we find that the vertex other than A and B which
corresponds to the smallest entry is C. Let us connect C to {A, B} at B.
Next, we examine the C-row and pick the vertex in this row having the
smallest entry which corresponds to D. Let us choose the edge {C, D}. By examining the
C- and D-rows, we find that the vertex other than C and D which corresponds to the
smallest entry and which does not produce a cycle is E. Let us connect E to {C, D} at D.
The construction at this stage shows that the edges {A, B}, {B, C}, {C, D},
{D, E} belong to a minimal tree. The vertex left over is F, which is joined to A, D and E
in the given graph. Among the edges that contain F, the edges FA and FE have equal
minimum weights. Therefore, we can include either of these in the minimal spanning tree.
Thus, for the given graph we get two minimal spanning trees shown below:
0A
A
1 3 1
F B F B
3 2 2
C E
E C
4 2 4 D 2
D
(a) (b)
We note that the weight of each of the above tees is 12 units.
Problem: Using Prim’s algorithm, find a minimal spanning tree for the weighted graph
shown below:
v5 10
8 v1
9
17 11
v6 7 v4 10
16
v2
12 7 9.5
v3 19.5
Solution: We note that the given graph has 6 vertices. Therefore, a minimal spanning tree
thereof has 5 edges. Let us prepare the following table of weights of edges.
v1 v2 v3 v4 v5 v6
v1 - 10 16 11 10 17
v2 10 - 9.5 19.5
v3 10 9.5 - 7 12
v4 11 7 - 8 7
v5 10 8 - 9
v6 17 19.5 12 7 9 -
Now, we start with the first row and pick the smallest entry therein. This is 10
which corresponds to the edges {v1, v2} or {v1, v5}. Let us select one of these edges, say
{v1, v5}. Now, by examining all the entries in v1- and v5 rows, we find that the vertex
other than v1 and v5 which corresponds to the smallest entry is v4. Let us connect v4 to the
edge {v1, v5} at v5.
Let us now examine the v4-row and note that the smallest entry therein is 7.
Which corresponds to the edges {v4, v3} and {v4, v6}. Let us choose one of these, say
{v4, v6}. BY examining the entries in v4- and v6 rows, we find that the vertex other than
v4 and v6 which corresponds to the smallest entry is v3. Let us connect v3 to the edge
{v4, v6} at v4.
Let us examine the v3- row and pick the vertex v4 which corresponds to the
smallest entry. By examining the entries in v3- and v4- rows, we find that the vertex other
than v3 and v4 which corresponds to the smallest entry is v2. Let us connect v2 to {v3, v4}
at v3.
We stop the process, because we have now connected all the six vertices with
five edges: {v1, v5}, {v5, v54}, {v4, v6}, {v4, v3}, {v3, v2}. The corresponding graph is as
shown below. This graph constitutes a minimal spanning tree of the given graph. We note
that its weights is 41.5 units.
v5 10 v1
8
v6 7 v4
7
v3 9.5 v2