]> mj.ucw.cz Git - saga.git/blob - mst.tex
Finished the RB alg.
[saga.git] / mst.tex
1 \ifx\endpart\undefined
2 \input macros.tex
3 \fi
4
5 \chapter{Minimum Spanning Trees}
6
7 \section{The Problem}
8
9 The problem of finding a minimum spanning tree of a weighted graph is one of the
10 best studied problems in the area of combinatorial optimization since its birth.
11 Its colorful history (see \cite{graham:msthistory} and \cite{nesetril:history} for the full account)
12 begins in~1926 with the pioneering work of Bor\accent23uvka
13 \cite{boruvka:ojistem}\foot{See \cite{nesetril:boruvka} for an English translation with commentary.},
14 who studied primarily an Euclidean version of the problem related to planning
15 of electrical transmission lines (see \cite{boruvka:networks}), but gave an efficient
16 algorithm for the general version of the problem. As it was well before the dawn of graph
17 theory, the language of his paper was complicated, so we will better state the problem
18 in contemporary terminology:
19
20 \proclaim{Problem}Given an undirected graph~$G$ with weights $w:E(G)\rightarrow {\bb R}$,
21 find its minimum spanning tree, defined as follows:
22
23 \defn\thmid{mstdef}%
24 For a given graph~$G$ with weights $w:E(G)\rightarrow {\bb R}$:
25 \itemize\ibull
26 \:A~subgraph $H\subseteq G$ is called a \df{spanning subgraph} if $V(H)=V(G)$.
27 \:A~\df{spanning tree} of $G$ is any its spanning subgraph which is a tree.
28 \:For any subgraph $H\subseteq G$ we define its \df{weight} $w(H):=\sum_{e\in E(H)} w(e)$.
29 \:A~\df{minimum spanning tree (MST)} of~$G$ is a spanning tree~$T$ such that its weight $w(T)$
30   is the smallest possible of all the spanning trees of~$G$.
31 \:For a disconnected graph, a \df{(minimum) spanning forest (MSF)} is defined as
32   a union of (minimum) spanning trees of its connected components.
33 \endlist
34
35 Bor\accent23uvka's work was further extended by Jarn\'\i{}k \cite{jarnik:ojistem}, again in
36 mostly geometric setting, giving another efficient algorithm. However, when
37 computer science and graph theory started forming in the 1950's and the
38 spanning tree problem was one of the central topics of the flourishing new
39 disciplines, the previous work was not well known and the algorithms had to be
40 rediscovered several times.
41
42 Recently, several significantly faster algorithms were discovered, most notably the
43 $\O(m\beta(m,n))$-time algorithm by Fredman and Tarjan \cite{ft:fibonacci} and
44 algorithms with inverse-Ackermann type complexity by Chazelle \cite{chazelle:ackermann}
45 and Pettie \cite{pettie:ackermann}.
46
47 \FIXME{Write the rest of the history.}
48
49 This chapter attempts to survery the important algorithms for finding the MST and it
50 also presents several new ones.
51
52 \section{Basic Properties}
53
54 In this section, we will examine the basic properties of spanning trees and prove
55 several important theorems to base the algorithms upon. We will follow the theory
56 developed by Tarjan in~\cite{tarjan:dsna}.
57
58 For the whole section, we will fix a graph~$G$ with edge weights~$w$ and all
59 other graphs will be spanning subgraphs of~$G$. We will use the same notation
60 for the subgraphs as for the corresponding sets of edges.
61
62 First of all, let us show that the weights on edges are not necessary for the
63 definition of the MST. We can formulate an equivalent characterization using
64 an ordering of edges instead.
65
66 \defnn{Heavy and light edges}\thmid{heavy}%
67 Let~$T$ be a~spanning tree. Then:
68 \itemize\ibull
69 \:For vertices $x$ and $y$, let $T[x,y]$ denote the (unique) path in~$T$ joining $x$ and~$y$.
70 \:For an edge $e=xy$ we will call $T[e]:=T[x,y]$ the \df{path covered by~$e$} and
71   the edges of this path \df{edges covered by~$e$}.
72 \:An edge~$e$ is called \df{light with respect to~$T$} (or just \df{$T$-light}) if it covers a heavier edge, i.e., if there
73   is an edge $f\in T[e]$ such that $w(f) > w(e)$.
74 \:An edge~$e$ is called \df{$T$-heavy} if it is not $T$-light.
75 \endlist
76
77 \rem
78 Please note that the above properties also apply to tree edges
79 which by definition cover only themselves and therefore they are always heavy.
80
81 \lemman{Light edges}\thmid{lightlemma}%
82 Let $T$ be a spanning tree. If there exists a $T$-light edge, then~$T$
83 is not minimum.
84
85 \proof
86 If there is a $T$-light edge~$e$, then there exists an edge $e'\in T[e]$ such
87 that $w(e')>w(e)$. Now $T-e'$ is a forest of two trees with endpoints of~$e$
88 located in different components, so adding $e$ to this forest must restore
89 connectivity and $T':=T-e'+e$ is another spanning tree with weight $w(T')
90 = w(T)-w(e')+w(e) < w(T)$. Hence $T$ could not have been minimum.
91 \qed
92
93 \figure{mst2.eps}{278pt}{An edge exchange as in the proof of Lemma~\thmref{lightlemma}}
94
95 The converse of this lemma is also true and to prove it, we will once again use
96 technique of transforming trees by \df{exchanges} of edges. In the proof of the
97 lemma, we have made use of the fact that whenever we exchange an edge~$e$ of
98 a spanning tree for another edge~$f$ covered by~$e$, the result is again
99 a spanning tree. In fact, it is possible to transform any spanning tree
100 to any other spanning tree by a sequence of exchanges.
101
102 \lemman{Exchange property for trees}\thmid{xchglemma}%
103 Let $T$ and $T'$ be spanning trees of a common graph. Then there exists
104 a sequence of edge exchanges which transforms $T$ to~$T'$. More formally,
105 there exists a sequence of spanning trees $T=T_0,T_1,\ldots,T_k=T'$ such that
106 $T_{i+1}=T_i - e_i + e_i^\prime$ where $e_i\in T_i$ and $e_i^\prime\in T'$.
107
108 \proof
109 By induction on $d(T,T'):=\vert T\symdiff T'\vert$. When $d(T,T')=0$,
110 both trees are identical and no exchanges are needed. Otherwise, the trees are different,
111 but as they are of the same size, there must exist an edge $e'\in T'\setminus T$.
112 The cycle $T[e']+e'$ cannot be wholly contained in~$T'$, so there also must
113 exist an edge $e\in T[e']\setminus T'$. Exchanging $e$ for~$e'$ yields a spanning
114 tree $T^*:=T-e+e'$ such that $d(T^*,T')=d(T,T')-2$ and we can apply the induction
115 hypothesis to $T^*$ and $T'$ to get the rest of the exchange sequence.
116 \qed
117
118 \figure{mst1.eps}{295pt}{One step of the proof of Lemma~\thmref{xchglemma}}
119
120 \lemman{Monotone exchanges}\thmid{monoxchg}%
121 Let $T$ be a spanning tree such that there are no $T$-light edges and $T'$
122 be an arbitrary spanning tree. Then there exists a sequence of edge exchanges
123 transforming $T$ to~$T'$ such that the weight does not increase in any step.
124
125 \proof
126 We improve the argument from the previous proof, refining the induction step.
127 When we exchange $e\in T$ for $e'\in T'\setminus T$ such that $e\in T[e']$,
128 the weight never drops, since $e'$ is not a $T$-light edge and therefore
129 $w(e') \ge w(e)$, so $w(T^*)=w(T)-w(e)+w(e')\ge w(T)$.
130
131 To keep the induction going, we have to make sure that there are still no light
132 edges with respect to~$T^*$. In fact, it is enough to avoid such edges in
133 $T'\setminus T^*$, since these are the only edges considered by the induction
134 steps. To accomplish that, we replace the so far arbitrary choice of $e'\in T'\setminus T$
135 by picking the lightest such edge.
136
137 Now consider an edge $f\in T'\setminus T^*$. We want to show that $f$ is not
138 $T^*$-light, i.e., that it is heavier than all edges on $T^*[f]$. The path $T^*[f]$ is
139 either equal to the original path $T[f]$ (if $e\not\in T[f]$) or to $T[f] \symdiff C$,
140 where $C$ is the cycle $T[e']+e'$. The former case is trivial, in the latter one
141 $w(f)\ge w(e')$ due to the choice of $e'$ and all other edges on~$C$ are lighter
142 than~$e'$ as $e'$ was not $T$-light.
143 \qed
144
145 \theorem\thmid{mstthm}%
146 A~spanning tree~$T$ is minimum iff there is no $T$-light edge.
147
148 \proof
149 If~$T$ is minimum, then by Lemma~\thmref{lightlemma} there are no $T$-light
150 edges.
151 Conversely, when $T$ is a spanning tree without $T$-light edges
152 and $T_{min}$ is an arbitrary minimum spanning tree, then according to the Monotone
153 exchange lemma (\thmref{monoxchg}) there exists a non-decreasing sequence
154 of exchanges transforming $T$ to $T_{min}$, so $w(T)\le w(T_{min})$
155 and thus $T$~is also minimum.
156 \qed
157
158 In general, a single graph can have many minimum spanning trees (for example
159 a complete graph on~$n$ vertices and unit edge weights has $n^{n-2}$
160 minimum spanning trees according to the Cayley's formula \cite{cayley:trees}).
161 However, as the following theorem shows, this is possible only if the weight
162 function is not injective.
163
164 \theoremn{MST uniqueness}
165 If all edge weights are distinct, then the minimum spanning tree is unique.
166
167 \proof
168 Consider two minimum spanning trees $T_1$ and~$T_2$. According to the previous
169 theorem, there are no light edges with respect to neither of them, so by the
170 Monotone exchange lemma (\thmref{monoxchg}) there exists a sequence of non-decreasing
171 edge exchanges going from $T_1$ to $T_2$. As all edge weights all distinct,
172 these edge exchanges must be in fact strictly increasing. On the other hand,
173 we know that $w(T_1)=w(T_2)$, so the exchange sequence must be empty and indeed
174 $T_1$ and $T_2$ must be identical.
175 \qed
176
177 \rem\thmid{edgeoracle}%
178 To simplify the description of MST algorithms, we will expect that the weights
179 of all edges are distinct and that instead of numeric weights (usually accompanied
180 by problems with representation of real numbers in algorithms) we will be given
181 a comparison oracle, that is a function which answers questions ``$w(e)<w(f)$?'' in
182 constant time. In case the weights are not distinct, we can easily break ties by
183 comparing some unique edge identifiers and according to our characterization of
184 minimum spanning trees, the unique MST of the new graph will still be a MST of the
185 original graph. In the few cases where we need a more concrete input, we will
186 explicitly state so.
187
188 \section{The Red-Blue Meta-Algorithm}
189
190 Most MST algorithms can be described as special cases of the following procedure
191 (again following \cite{tarjan:dsna}):
192
193 \algn{Red-Blue Meta-Algorithm}
194 \algo
195 \algin A~graph $G$ with an edge comparison oracle (see \thmref{edgeoracle})
196 \:In the beginning, all edges are colored black.
197 \:Apply rules as long as possible:
198 \::Either pick a cut~$C$ such that its lightest edge is not blue \hfil\break and color this edge blue, \cmt{Blue rule}
199 \::Or pick a cycle~$C$ such that its heaviest edge is not red \hfil\break and color this edge \hphantas{red.}{blue.} \cmt{Red rule}
200 \algout Minimum spanning tree of~$G$ consisting of edges colored blue.
201 \endalgo
202
203 \rem
204 This procedure is not a proper algorithm, since it does not specify how to choose
205 the rule to apply. We will however prove that no matter how the rules are applied,
206 the procedure always stops and gives the correct result. Also, it will turn out
207 that each of the classical MST algorithms can be described as a specific way
208 of choosing the rules in this procedure, which justifies the name meta-algorithm.
209
210 \proclaim{Notation}%
211 We will denote the unique minimum spanning tree of the input graph by~$T_{min}$.
212 We intend to prove that this is also the output of the procedure.
213
214 \lemman{Blue lemma}
215 When an edge is colored blue in any step of the procedure, it is contained in the minimum spanning tree.
216
217 \proof
218 By contradiction. Let $e$ be an edge painted blue as the lightest edge of a cut~$C$.
219 If $e\not\in T_{min}$, then there must exist an edge $e'\in T_{min}$ which is
220 contained in~$C$ (take any pair of vertices separated by~$C$, the path
221 in~$T_{min}$ joining these vertices must cross~$C$ at least once). Exchanging
222 $e$ for $e'$ in $T_{min}$ yields an even lighter spanning tree since
223 $w(e)<w(e')$. \qed
224
225 \lemman{Red lemma}
226 When an edge is colored red in any step of the procedure, it is not contained in the minimum spanning tree.
227
228 \proof
229 Again by contradiction. Assume that $e$ is an edge painted red as the heaviest edge
230 of a cycle~$C$ and that $e\in T_{min}$. Removing $e$ causes $T_{min}$ to split to two
231 components, let us call them $T_x$ and $T_y$. Some vertices of~$C$ now lie in $T_x$,
232 the others in $T_y$, so there must exist in edge $e'\ne e$ such that its endpoints
233 lie in different components. Since $w(e')<w(e)$, exchanging $e$ for~$e'$ yields
234 a lighter spanning tree than $T_{min}$.
235 \qed
236
237 \figure{mst-rb.eps}{289pt}{Proof of the Blue (left) and Red (right) lemma}
238
239 \lemman{Black lemma}
240 As long as there exists a black edge, at least one rule can be applied.
241
242 \proof
243 Assume that $e=xy$ be a black edge. Let us denote $M$ the set of vertices
244 reachable from~$x$ using only blue edges. If $y$~lies in~$M$, then $e$ together
245 with some blue path between $x$ and $y$ forms a cycle and it must be the heaviest
246 edge on this cycle. This holds because all blue edges have been already proven
247 to be in $T_{min}$ and there can be no $T_{min}$-light edges (see Theorem~\thmref{mstthm}).
248 In this case we can apply the red rule.
249
250 On the other hand, if $y\not\in M$, then the cut formed by all edges between $M$
251 and $V(G)\setminus M$ contains no blue edges, therefore we can use the blue rule.
252 \qed
253
254 \figure{mst-bez.eps}{295pt}{Configurations in the proof of the Black lemma}
255
256 \theoremn{Red-Blue correctness}
257 For any selection of rules, the Red-Blue procedure stops and the blue edges form
258 the minimum spanning tree of the input graph.
259
260 \proof
261 To prove that the procedure stops, let us notice that no edge is ever recolored,
262 so we must run out of black edges after at most $m$ steps. Recoloring
263 to the same color is avoided by the conditions built in the rules, recoloring to
264 a different color would mean that the an edge would be both inside and outside~$T_{min}$
265 due to our Red and Blue lemmata.
266
267 When no further rules can be applied, the Black lemma guarantees that all edges
268 are colored, so by the Blue lemma all blue edges are in~$T_{min}$ and by the Red
269 lemma all other (red) edges are outside~$T_{min}$, so the blue edges are exactly~$T_{min}$.
270 \qed
271
272
273
274 % mention Steiner trees
275 % mention matroids
276 % sorted weights
277
278 \endpart