1 Exercises: 1.1 Spanning Trees
1 Exercises: 1.1 Spanning Trees
1 Exercises: 1.1 Spanning Trees
1
Workers can be discharged from the building site only in the beginning of
the month. Suppose that in February and in September there is exactly
three workers at the building site.
The aim of the contractor is to plan an allocation of workers which mini-
mizes the sum of the following costs :
• Transfer cost. Hiring a worker to the building site costs 50 euros and
discharging a worker costs 80 euros.
• Transfer rules. The contractor can hire at most 3 workers at a time
and can discharge at most one third of his stuff at a time.
• Over and underpopulation costs. A superfluous worker costs 100
euros, whereas missing of one worker costs 200 euros. When some
stuff is missing, workers take additional working hours, but they do
not accept to work additionaly more than 1/4 of their normal time.
Formulate this problem as a shortest path problem and solve it using the
Dijsktra’s algorithm.
2. You possess a bank-note of p euros and you want to change it to coins of
a1 , a2 , . . . , an euros. Is it possible? If yes, what is the minimum number
of coins? Formulate this problem as a shortest path problem and solve it
using the Dijsktra’s algorithm.
3. Let dk (j) be the length of the shortest path between from vertice s to k
with k edges at most. Find a recursion for dk (j). Prove that dn−1 (j) =
D(j) = the shortest distance from s to j. Here n is the number of vertices
in the graph.
2 Solutions
2.1 Spanning trees
1. To find the minimum cost road network, we formulate the problem as a
minimum weight spanning tree problem. Consider the complete graph
with 5 vertices. The weight of edge (i, j), i, j ∈ {1, . . . , 5}, is set to aij .
Now we find the minimum weight spanning tree of the graph constructed.
The tree found is {(1, 2), (2, 3), (2, 5), (4, 5)} and the total cost is 21.
2. (a) Let T be a minimum weight spanning tree in graph G and T does
not contain edge e = (u, v). We add edge e to the spanning tree T .
By the property of trees, T now contains a cycle and e is one of edges
in this cycle. Now we remove from T an arbitrary edge e′ 6= e which
belongs to the cycle. We obtain a new spanning tree T ′ . The weight
of spanning tree T ′ is not more than the weight of spanning tree T ,
as the weight of e is not more than the weight of e′ . Therefore T ′ is
also a minimum weight spanning tree in graph G and T ′ contains e.
2
(b) Let T is a minimum weight spanning tree in graph G and T contains
edge e. T cannot contain all the edges from the cycle and we can
replace in T the edge e by another edge e′ which belongs to the cycle
and is not contained in T . We obtain a new spanning tree T ′ . The
weight of the spanning tree T ′ is not more than the weight of the
spanning tree T , as the weight of e is not more than the weight of e′ .
Therefore T ′ is also a minimum weight spanning tree in the graph
G. Moreover T ′ is also a minimum weight spanning tree in the graph
G′ = (V, E \ {e}), as T ′ does not contain the edge e and graphs G
and G′ have the same number of vertices.
(c) Suppose that T ′ is not a minimum weight spanning tree in graph G′
and S ′ is a minimum weight spanning tree in G′ . Then, if we joined
the subset of edges T \ T ′ to S ′ , then we would obtain a spanning tree
S in the graph G. The weight of S would be smaller than the weight
of T and this contradicts the condition that T is a minimum weight
spanning tree. Thus, our assumption is false and T ′ is a minimum
weight spanning tree in the graph G′ .
(d) Let T is a minimum weight spanning tree in a graph G and T does
not contain the edge e. We add e to the spanning tree T and obtain
a cycle. This cycle should contain besides e another edge e′ which
connects subsets of vertexes V ′ and V \ V ′ . We remove e′ from T
and obtain a spanning tree T ′ . The weight of T ′ is not more than the
weight of the spanning tree T , as the weight of e is not more than
the weight of e′ . Therefore T ′ is also a minimum weight spanning
tree in the graph G and T ′ contains e.
3. It is easy to see that it is always possible if and only if G is connected. If
G is not connected then there is no connected sub-graph of G, therefore
there is no spanning tree. Suppose now that G is connected. Consider a
spanning tree T of G. If e is in T , we are done. Otherwise we add e to T .
By the property of trees, T now contains a cycle and e is one of edges in
this cycle. Now we remove from T an arbitrary edge e′ 6= e which belongs
to the cycle. We obtain a new spanning tree T ′ which containts e.
If we are given a set S of edges then it is possible to construct a spanning
tree containing this set if and only if G is connected and no subset of S is
a cycle. To construct a spanning tree containing set S of edges, we again
start from an arbitrary spanning tree T of G and proceed iteratively. On
each iteration, we insert an edge from S \ T and then delete an edge in
T \ S from the cycle formed in T .
4. There are several ways to modify the Prim’s algorithm in order to take
into account this additional constraint. One of them is the following.
Given a graph G = (V, E), let S be the set of edges that represents our
additional constraint, i.e. S is the set of edges which should be included
in the spanning tree. Now set the weight of all the edges in S to some
value which is less than the minimum weigth of edges in E \ S. Then we
3
run the Prim’s algorithm on the graph with modified weights. The cost
of the spanning tree found is calculated using the original weights.
1 1 1 1
1 1 1 1 j
1- j
1- j
1- j
1-
- - - -
0 1 2 3 4 5 6 7 8
> > > > > >
1 1 1 1 1 1
The proof of the fact that dn−1 (j) is the length of the shortest path be-
tween s and j follows from the observation that a shortest path between
s and j has at most n − 1 edges.