]> mj.ucw.cz Git - saga.git/blob - abstract.tex
More abstract art.
[saga.git] / abstract.tex
1 \input macros.tex
2 \finalfalse  %%FIXME
3
4 \def\rawchapter#1{\vensure{0.5in}\bigbreak\bigbreak
5 \leftline{\chapfont #1}
6 }
7
8 \def\rawsection#1{\bigskip
9 \leftline{\secfont #1}
10 \nobreak
11 \medskip
12 \nobreak
13 }
14
15 \chapter{Introduction}
16 \bigskip
17
18 This thesis tells the story of two well-established problems of algorithmic
19 graph theory: the minimum spanning trees and ranks of permutations. At distance,
20 both problems seem to be simple, boring and already solved, because we have poly\-nom\-ial-time
21 algorithms for them since ages. But when we come closer and seek algorithms that
22 are really efficient, the problems twirl and twist and withstand many a~brave
23 attempt at the optimum solution. They also reveal a~vast and diverse landscape
24 of a~deep and beautiful theory. Still closer, this landscape turns out to be interwoven
25 with the intricate details of various models of computation and even of arithmetics
26 itself.
27
28 We have tried to cover all known important results on both problems and unite them
29 in a~single coherent theory. At many places, we have attempted to contribute my own
30 little stones to this mosaic: several new results, simplifications of existing
31 ones, and last, but not least filling in important details where the original
32 authors have missed some.
33
34 When compared with the earlier surveys on the minimum spanning trees, most
35 notably Graham and Hell \cite{graham:msthistory} and Eisner \cite{eisner:tutorial},
36 this work adds many of the recent advances, the dynamic algorithms and
37 also the relationship with computational models. No previous work covering
38 the ranking problems in their entirety is known.
39
40 We~have tried to stick to the usual notation except where it was too inconvenient.
41 Most symbols are defined at the place where they are used for the first time.
42 To avoid piling up too many symbols at places that speak about a~single fixed graph,
43 this graph is always called~$G$, its set of vertices and edges are denoted by $V$
44 and~$E$ respectively, and we~also use~$n$ for the number of its vertices and $m$~for
45 the number of edges. At places where there could be a~danger of confusion, more explicit notation
46 is used instead.
47
48 \chapter{Minimum Spanning Trees}
49
50 \section{The Problem}
51
52 The problem of finding a minimum spanning tree of a weighted graph is one of the
53 best studied problems in the area of combinatorial optimization since its birth.
54 Its colorful history (see \cite{graham:msthistory} and \cite{nesetril:history} for the full account)
55 begins in~1926 with the pioneering work of Bor\o{u}vka
56 \cite{boruvka:ojistem}\foot{See \cite{nesetril:boruvka} for an English translation with commentary.},
57 who studied primarily an Euclidean version of the problem related to planning
58 of electrical transmission lines (see \cite{boruvka:networks}), but gave an efficient
59 algorithm for the general version of the problem. As it was well before the dawn of graph
60 theory, the language of his paper was complicated, so we will better state the problem
61 in contemporary terminology:
62
63 \proclaim{Problem}Given an undirected graph~$G$ with weights $w:E(G)\rightarrow {\bb R}$,
64 find its minimum spanning tree, defined as follows:
65
66 \defn\id{mstdef}%
67 For a given graph~$G$ with weights $w:E(G)\rightarrow {\bb R}$:
68 \itemize\ibull
69 \:A~subgraph $H\subseteq G$ is called a \df{spanning subgraph} if $V(H)=V(G)$.
70 \:A~\df{spanning tree} of~$G$ is any spanning subgraph of~$G$ that is a tree.
71 \:For any subgraph $H\subseteq G$ we define its \df{weight} $w(H):=\sum_{e\in E(H)} w(e)$.
72 \:A~\df{minimum spanning tree (MST)} of~$G$ is a spanning tree~$T$ such that its weight $w(T)$
73   is the smallest possible among all the spanning trees of~$G$.
74 \:For a disconnected graph, a \df{(minimum) spanning forest (MSF)} is defined as
75   a union of (minimum) spanning trees of its connected components.
76 \endlist
77
78 Bor\o{u}vka's work was further extended by Jarn\'\i{}k \cite{jarnik:ojistem}, again in
79 mostly geometric setting, and he has discovered another efficient algorithm.
80 In the next 50 years, several significantly faster algorithms were published, ranging
81 from the $\O(m\timesbeta(m,n))$ time algorithm by Fredman and Tarjan \cite{ft:fibonacci},
82 over algorithms with inverse-Ackermann type complexity by Chazelle \cite{chazelle:ackermann}
83 and Pettie \cite{pettie:ackermann}, to an~algorithm by Pettie \cite{pettie:optimal}
84 whose time complexity is provably optimal.
85
86 Before we discuss the algorithms, let us review the basic properties of spanning trees.
87 We will mostly follow the theory developed by Tarjan in~\cite{tarjan:dsna} and show
88 that the weights on edges are not necessary for the definition of the MST.
89
90 \defnn{Heavy and light edges}\id{heavy}%
91 Let~$G$ be a~connected graph with edge weights~$w$ and $T$ its spanning tree. Then:
92 \itemize\ibull
93 \:For vertices $x$ and $y$, let $T[x,y]$ denote the (unique) path in~$T$ joining $x$ with~$y$.
94 \:For an edge $e=xy$ we will call $T[e]:=T[x,y]$ the \df{path covered by~$e$} and
95   the edges of this path \df{edges covered by~$e$}.
96 \: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
97   is an~edge $f\in T[e]$ such that $w(f) > w(e)$.
98 \:An edge~$e$ is called \df{$T$-heavy} if it covers a~lighter edge.
99 \endlist
100
101 \thm
102 A~spanning tree~$T$ is minimum iff there is no $T$-light edge.
103
104 \thm
105 If all edge weights are distinct, then the minimum spanning tree is unique.
106
107 \para
108 When $G$ is a graph with distinct edge weights, we will use $\mst(G)$ to denote
109 its unique minimum spanning tree.
110 To simplify the description of MST algorithms, we will assume that the weights
111 of all edges are distinct and that instead of numeric weights we are given a~\df{comparison oracle.}
112 The oracle is a~function that answers questions of type ``Is $w(e)<w(f)$?'' in
113 constant time. This will conveniently shield us from problems with representation
114 of real numbers in algorithms and in the few cases where we need a more concrete
115 input, we will explicitly state so. In case the weights are not distinct, the ties
116 can be broken arbitrarily.
117
118 \section{Classical algorithms}
119
120 The characterization of MST's in terms of light edges makes it easy to develop
121 the Tarjan's Red-Blue meta-algorithm, which is based on the following properties:
122
123 \lemman{Blue lemma, also known as the Cut rule}\id{bluelemma}%
124 The lightest edge of every cut is contained in the MST.
125
126 \lemman{Red lemma, also known as the Cycle rule}\id{redlemma}%
127 An~edge~$e$ is not contained in the MST iff it is the heaviest on some cycle.
128
129 The algorithm repeatedly colors lightest edges of cuts blue and heaviest
130 edges of cycles red. We prove that no matter which order of the colorings
131 we use, the algorithm always stops and the blue edges form the MST.
132
133 All three classical MST algorithms (Bor\o{u}vka's, Jarn\'\i{}k's and Kruskal's)
134 can be then obtained as specializations of this procedure. We also calculate the
135 time complexity of standard implementations of these algorithms.
136
137 \algn{Bor\o{u}vka \cite{boruvka:ojistem}, Choquet \cite{choquet:mst}, Sollin \cite{sollin:mst}, and others}
138 \algo
139 \algin A~graph~$G$ with an edge comparison oracle.
140 \:$T\=$ a forest consisting of vertices of~$G$ and no edges.
141 \:While $T$ is not connected, perform a~\df{Bor\o{u}vka step:}
142 \::For each component $T_i$ of~$T$, choose the lightest edge $e_i$ from the cut
143    separating $T_i$ from the rest of~$T$.
144 \::Add all $e_i$'s to~$T$.
145 \algout Minimum spanning tree~$T$.
146 \endalgo
147
148 \thm
149 The Bor\o{u}vka's algorithm finds the MST in time $\O(m\log n)$.
150
151 \algn{Jarn\'\i{}k \cite{jarnik:ojistem}, Prim \cite{prim:mst}, Dijkstra \cite{dijkstra:mst}}\id{jarnik}%
152 \algo
153 \algin A~graph~$G$ with an edge comparison oracle.
154 \:$T\=$ a single-vertex tree containing an~arbitrary vertex of~$G$.
155 \:While there are vertices outside $T$:
156 \::Pick the lightest edge $uv$ such that $u\in V(T)$ and $v\not\in V(T)$.
157 \::$T\=T+uv$.
158 \algout Minimum spanning tree~$T$.
159 \endalgo
160
161 \thm
162 The Jarn\'\i{}k's algorithm computes the MST of a~given graph in time $\O(m\log n)$.
163
164 \algn{Kruskal \cite{kruskal:mst}}
165 \algo
166 \algin A~graph~$G$ with an edge comparison oracle.
167 \:Sort edges of~$G$ by their increasing weights.
168 \:$T\=\hbox{an empty spanning subgraph}$.
169 \:For all edges $e$ in their sorted order:
170 \::If $T+e$ is acyclic, add~$e$ to~$T$.
171 \::Otherwise drop~$e$.
172 \algout Minimum spanning tree~$T$.
173 \endalgo
174
175 \thm
176 The Kruskal's algorithm finds the MST of a given graph in time $\O(m\log n)$.
177 If the edges are already sorted by their weights, the time drops to
178 $\O(m\timesalpha(m,n))$.\foot{Here $\alpha(m,n)$ is a~certain inverse of the Ackermann's
179 function.}
180
181 \section{Contractive algorithms}\id{contalg}%
182
183 While the classical algorithms are based on growing suitable trees, they
184 can be also reformulated in terms of edge contraction. Instead of keeping
185 a~forest of trees, we can keep each tree contracted to a single vertex.
186 This replaces the relatively complex tree-edge incidencies by simple
187 vertex-edge incidencies, potentially speeding up the calculation at the
188 expense of having to perform the contractions.
189 A~contractive version of the Bor\o{u}vka's algorithm is easy to formulate
190 and also to analyse:
191
192 \algn{Contractive version of Bor\o{u}vka's algorithm}\id{contbor}%
193 \algo
194 \algin A~graph~$G$ with an edge comparison oracle.
195 \:$T\=\emptyset$.
196 \:$\ell(e)\=e$ for all edges~$e$. \cmt{Initialize edge labels.}
197 \:While $n(G)>1$:
198 \::For each vertex $v_k$ of~$G$, let $e_k$ be the lightest edge incident to~$v_k$.
199 \::$T\=T\cup \{ \ell(e_1),\ldots,\ell(e_n) \}$.\hfil\break\cmt{Remember labels of all selected edges.}
200 \::Contract all edges $e_k$, inheriting labels and weights.\foot{In other words, we will ask the comparison oracle for the edge $\ell(e)$ instead of~$e$.}
201 \::Flatten $G$ (remove parallel edges and loops).
202 \algout Minimum spanning tree~$T$.
203 \endalgo
204
205 \thm
206 The Contractive Bor\o{u}vka's algorithm finds the MST of the input graph in
207 time $\O(\min(n^2,m\log n))$.
208
209 We also show that this time bound is tight --- we construct an~explicit
210 family of graphs on which the algorithm spends $\Theta(m\log n)$ steps.
211 Given a~planar graph, the algorithm however runs much faster (we get a~linear-time
212 algorithm much simpler than the one of Matsui \cite{matsui:planar}):
213
214 \thm
215 When the input graph is planar, the Contractive Bor\o{u}vka's algorithm runs in
216 time $\O(n)$.
217
218 Graph contractions are indeed a~very powerful tool and they can be used in other MST
219 algorithms as well. The following lemma shows the gist:
220
221 \lemman{Contraction lemma}\id{contlemma}%
222 Let $G$ be a weighted graph, $e$~an arbitrary edge of~$\mst(G)$, $G/e$ the multigraph
223 produced by contracting~$e$ in~$G$, and $\pi$ the bijection between edges of~$G-e$ and
224 their counterparts in~$G/e$. Then $\mst(G) = \pi^{-1}[\mst(G/e)] + e.$
225
226 \chapter{Fine Details of Computation}
227
228 \section{Models and machines}
229
230 Traditionally, computer scientists have been using a~variety of computational models
231 as a~formalism in which their algorithms are stated. If we were studying
232 NP-complete\-ness, we could safely assume that all these models are equivalent,
233 possibly up to polynomial slowdown which is negligible. In our case, the
234 differences between good and not-so-good algorithms are on a~much smaller
235 scale, so we need to state our computation models carefully and develop
236 a repertoire of basic data structures tailor-made for the fine details of the
237 models.
238
239 In recent decades, most researchers in the area of combinatorial algorithms
240 have been considering two computational models: the Random Access Machine and the Pointer
241 Machine. The former is closer to the programmer's view of a~real computer,
242 the latter is slightly more restricted and ``asymptotically safe.''
243 We will follow this practice and study our algorithms in both models.
244
245 The \df{Random Access Machine (RAM)} is not a~single coherent model, but rather a~family
246 of closely related machines (See Cook and Reckhow \cite{cook:ram} for one of the usual formal definitions
247 and Hagerup \cite{hagerup:wordram} for a~thorough description of the differences
248 between the RAM variants.) We will consider the variant usually called the \df{Word-RAM.}
249 It allows the ``C-language operators'', i.e., arithmetics and bitwise logical operations,
250 running in constant time on words of a~specified size.
251
252 The \df{Pointer Machine (PM)} also does not seem to have any well established definition.
253 The various kinds of pointer machines are examined by Ben-Amram in~\cite{benamram:pm},
254 but unlike the RAM's they turn out to be equivalent up to constant slowdown.
255 Our formal definition is closely related to the \em{linking automaton} proposed
256 by Knuth in~\cite{knuth:fundalg}.
257
258 \section{Pointer machine techniques}\id{bucketsort}%
259
260 In the Contractive Bor\o{u}vka's algorithm, we needed to contract a~given
261 set of edges in the current graph and then flatten the graph, all this in time $\O(m)$.
262 This can be easily handled on both the RAM and the PM by bucket sorting. We develop
263 a~bunch of pointer-based sorted techniques which can be summarized by the following
264 lemma:
265
266 \lemma
267 Partitioning of a~collection of sequences $S_1,\ldots,S_n$, whose elements are
268 arbitrary pointers and symbols from a~finite alphabet, to equality classes can
269 be performed on the Pointer Machine in time $\O(n + \sum_i \vert S_i \vert)$.
270
271 \para
272 A~direct consequence of this unification is a~linear-time algorithm for subtree
273 isomorphism, significantly simpler than the standard one due to Zemlayachenko (see \cite{zemlay:treeiso}
274 and also Dinitz et al.~\cite{dinitz:treeiso}). When we apply a~similar technique
275 to general graphs, we get the framework of topological graph computation
276 of Buchsbaum et al.~\cite{buchsbaum:verify}.
277
278 \defn
279 A~\df{graph computation} is a~function that takes a~\df{labeled undirected graph} as its input. The labels of
280 vertices and edges can be arbitrary symbols drawn from a~finite alphabet. The output
281 of the computation is another labeling of the same graph. This time, the vertices and
282 edges can be labeled with not only symbols of the alphabet, but also with pointers to the vertices
283 and edges of the input graph, and possibly also with pointers to outside objects.
284 A~graph computation is called \df{topological} if it produces isomorphic
285 outputs for isomorphic inputs. The isomorphism of course has to preserve not only
286 the structure of the graph, but also the labels in the obvious way.
287
288 \defn
289 For a~collection~$\C$ of graphs, we define $\vert\C\vert$ as the number of graphs in
290 the collection and $\Vert\C\Vert$ as their total size, i.e., $\Vert\C\Vert = \sum_{G\in\C} n(G) + m(G)$.
291
292 \thm
293 Suppose that we have a~topological graph computation~$\cal T$ that can be performed in time
294 $T(k)$ for graphs on $k$~vertices. Then we can run~$\cal T$ on a~collection~$\C$
295 of labeled graphs on~$k$ vertices in time $\O(\Vert\C\Vert + (k+s)^{k(k+2)}\cdot (T(k)+k^2))$,
296 where~$s$ is a~constant depending only on the number of symbols used as vertex/edge labels.
297
298 \section{Data structures on the RAM}\id{ramds}%
299
300 There is a~lot of data structures designed specifically for the RAM. These structures
301 take advantage of both indexing and arithmetics and they often surpass the known
302 lower bounds for the same problem on the~PM. In many cases, they achieve constant time
303 per operation, at least when either the magnitude of the values or the size of
304 the data structure is suitably bounded.
305
306 A~classical result of this type is the tree of van Emde Boas~\cite{boas:vebt}
307 which represent a~subset of the integers $\{0,\ldots,U-1\}$. It allows insertion,
308 deletion and order operations (minimum, maximum, successor etc.) in time $\O(\log\log U)$,
309 regardless of the size of the subset. If we replace the heap used in the Jarn\'\i{}k's
310 algorithm (\ref{jarnik}) by this structure, we immediately get an~algorithm
311 for finding the MST in integer-weighted graphs in time $\O(m\log\log w_{max})$,
312 where $w_{max}$ is the maximum weight.
313
314 A~real breakthrough has however been made by Fredman and Willard who introduced
315 the Fusion trees~\cite{fw:fusion}. They again perform membership and predecessor
316 operation on a~set of $n$~integers, but with time complexity $\O(\log_W n)$
317 per operation on a~Word-RAM with $W$-bit words. This of course assumes that
318 each element of the set fits in a~single word. As $W$ must at least~$\log n$,
319 the operations take $\O(\log n/\log\log n)$ time and thus we are able to sort $n$~integers
320 in time~$o(n\log n)$. This was a~beginning of a~long sequence of faster and
321 faster sorting algorithms, culminating with the work of Thorup and Han.
322 They have improved the time complexity of integer sorting to $\O(n\log\log n)$ deterministically~\cite{han:detsort}
323 and expected $\O(n\sqrt{\log\log n})$ for randomized algorithms~\cite{hanthor:randsort},
324 both in linear space.
325
326 The Fusion trees themselves have very limited use in graph algorithms, but the
327 principles behind them are ubiquitous in many other data structures and these
328 will serve us well and often. We are going to build the theory of Q-heaps,
329 which will later lead to a~linear-time MST algorithm for arbitrary integer weights.
330 Other such structures will help us in building linear-time RAM algorithms for computing the ranks
331 of various combinatorial structures in Chapter~\ref{rankchap}.
332
333 Outside our area, important consequences of RAM data structures include the
334 Thorup's $\O(m)$ algorithm for single-source shortest paths in undirected
335 graphs with positive integer weights \cite{thorup:usssp} and his $\O(m\log\log
336 n)$ algorithm for the same problem in directed graphs \cite{thorup:sssp}. Both
337 algorithms have been then significantly simplified by Hagerup
338 \cite{hagerup:sssp}.
339
340 Despite the progress in the recent years, the corner-stone of all RAM structures
341 is still the representation of combinatorial objects by integers introduced by
342 Fredman and Willard.
343
344 First of all, we observe that we can encode vectors in integers:
345
346 \notan{Bit strings}\id{bitnota}%
347 We will work with binary representations of natural numbers by strings over the
348 alphabet $\{\0,\1\}$: we will use $\(x)$ for the number~$x$ written in binary,
349 $\(x)_b$ for the same padded to exactly $b$ bits by adding leading zeroes,
350 and $x[k]$ for the value of the $k$-th bit of~$x$ (with a~numbering of bits such that $2^k[k]=1$).
351 The usual conventions for operations on strings will be utilized: When $s$
352 and~$t$ are strings, we write $st$ for their concatenation and
353 $s^k$ for the string~$s$ repeated $k$~times.
354 When the meaning is clear from the context,
355 we will use $x$ and $\(x)$ interchangeably to avoid outbreak of symbols.
356
357 \defn
358 The \df{bitwise encoding} of a~vector ${\bf x}=(x_0,\ldots,x_{d-1})$ of~$b$-bit numbers
359 is an~integer~$x$ such that $\(x)=\(x_{d-1})_b\0\(x_{d-2})_b\0\ldots\0\(x_0)_b$. In other
360 words, $x = \sum_i 2^{(b+1)i}\cdot x_i$. (We have interspersed the elements with \df{separator bits.})
361
362 \para
363 If we want to fit the whole vector in a~single machine word, the parameters $b$ and~$d$ must satisfy
364 the condition $(b+1)d\le W$ (where $W$~is the word size of the machine).
365 By using multiple-precision arithmetics, we can encode all vectors satisfying $bd=\O(W)$.
366 We describe how to translate simple vector manipulations to sequences of $\O(1)$ RAM operations
367 on their codes. For example, we can handle element-wise comparison of vectors, insertion
368 in a~sorted vector or shuffling elements of a~vector according to a~fixed permutation,
369 all in $\O(1)$ time. This also implies that several functions on numbers can be performed
370 in constant time, most notably binary logarithms.
371 The vector operations then serve as building blocks for construction of the Q-heaps. We get:
372
373 \thm
374 Let $W$ and~$k$ be positive integers such that $k=\O(W^{1/4})$. Let~$Q$
375 be a~Q-heap of at most $k$-elements of $W$~bits each. Then we can perform
376 Q-heap operations on~$Q$ (insertion, deletion, search for a~given value and search
377 for the $i$-th smallest element) in constant time on a~Word-RAM with word size~$W$,
378 after spending time $\O(2^{k^4})$ on the same RAM on precomputing of tables.
379
380 \cor
381 For every positive integer~$r$ and $\delta>0$ there exists a~data structure
382 capable of maintaining the minimum of a~set of at most~$r$ word-sized numbers
383 under insertions and deletions. Each operation takes $\O(1)$ time on a~Word-RAM
384 with word size $W=\Omega(r^{\delta})$, after spending time
385 $\O(2^{r^\delta})$ on precomputing of tables.
386
387 \chapter{Advanced MST Algorithms}
388
389 \section{Minor-closed graph classes}\id{minorclosed}%
390
391 The contractive algorithm given in Section~\ref{contalg} has been found to perform
392 well on planar graphs, but in the general case its time complexity was not linear.
393 Can we find any broader class of graphs where this algorithm is still efficient?
394 The right context turns out to be the minor-closed graph classes, which are
395 closed under contractions and have bounded density.
396
397 \defn\id{minordef}%
398 A~graph~$H$ is a \df{minor} of a~graph~$G$ (written as $H\minorof G$) iff it can be obtained
399 from a~subgraph of~$G$ by a sequence of simple graph contractions.
400
401 \defn
402 A~class~$\cal C$ of graphs is \df{minor-closed}, when for every $G\in\cal C$ and
403 every minor~$H$ of~$G$, the graph~$H$ lies in~$\cal C$ as well. A~class~$\cal C$ is called
404 \df{non-trivial} if at least one graph lies in~$\cal C$ and at least one lies outside~$\cal C$.
405
406 \example
407 Non-trivial minor-closed classes include:
408 \itemize\ibull
409 \:planar graphs,
410 \:graphs embeddable in any fixed surface (i.e., graphs of bounded genus),
411 \:graphs embeddable in~${\bb R}^3$ without knots or without interlocking cycles,
412 \:graphs of bounded tree-width or path-width.
413 \endlist
414
415 \para
416 Many of the nice structural properties of planar graphs extend to
417 minor-closed classes, too (see Lov\'asz \cite{lovasz:minors} for a~nice survey
418 of this theory and Diestel \cite{diestel:gt} for some of the deeper results).
419 For analysis of the contractive algorithm, we will make use of the bounded
420 density of minor-closed classes:
421
422 \defn\id{density}%
423 Let $G$ be a~graph and $\cal C$ be a class of graphs. We define the \df{edge density}
424 $\varrho(G)$ of~$G$ as the average number of edges per vertex, i.e., $m(G)/n(G)$. The
425 edge density $\varrho(\cal C)$ of the class is then defined as the infimum of $\varrho(G)$ over all $G\in\cal C$.
426
427 \thmn{Density of minor-closed classes, Mader~\cite{mader:dens}}
428 Every non-trivial minor-closed class of graphs has finite edge density.
429
430 \thmn{MST on minor-closed classes, Mare\v{s} \cite{mm:mst}}\id{mstmcc}%
431 For any fixed non-trivial minor-closed class~$\cal C$ of graphs, the Contractive Bor\o{u}vka's
432 algorithm (\ref{contbor}) finds the MST of any graph of this class in time
433 $\O(n)$. (The constant hidden in the~$\O$ depends on the class.)
434
435 \paran{Local contractions}\id{nobatch}%
436 The contractive algorithm uses ``batch processing'' to perform many contractions
437 in a single step. It is also possible to perform them one edge at a~time,
438 batching only the flattenings. A~contraction of an edge~$uv$ can be done in time~$\O(\deg(u))$,
439 so we have to make sure that there is a~steady supply of low-degree vertices.
440 It indeed is in minor-closed classes:
441
442 \lemman{Low-degree vertices}\id{lowdeg}%
443 Let $\cal C$ be a graph class with density~$\varrho$ and $G\in\cal C$ a~graph
444 with $n$~vertices. Then at least $n/2$ vertices of~$G$ have degree at most~$4\varrho$.
445
446 So we get the following algorithm:
447
448 \algn{Local Bor\o{u}vka's Algorithm, Mare\v{s} \cite{mm:mst}}%
449 \algo
450 \algin A~graph~$G$ with an edge comparison oracle and a~parameter~$t\in{\bb N}$.
451 \:$T\=\emptyset$.
452 \:$\ell(e)\=e$ for all edges~$e$.
453 \:While $n(G)>1$:
454 \::While there exists a~vertex~$v$ such that $\deg(v)\le t$:
455 \:::Select the lightest edge~$e$ incident with~$v$.
456 \:::Contract~$e$.
457 \:::$T\=T + \ell(e)$.
458 \::Flatten $G$, removing parallel edges and loops.
459 \algout Minimum spanning tree~$T$.
460 \endalgo
461
462 \thm
463 When $\cal C$ is a minor-closed class of graphs with density~$\varrho$, the
464 Local Bor\o{u}vka's Algorithm with the parameter~$t$ set to~$4\varrho$ 
465 finds the MST of any graph from this class in time $\O(n)$. (The constant
466 in the~$\O$ depends on~the class.)
467
468 \section{Iterated algorithms}\id{iteralg}%
469
470 We have seen that the Jarn\'\i{}k's Algorithm \ref{jarnik} runs in $\Theta(m\log n)$ time.
471 Fredman and Tarjan \cite{ft:fibonacci} have shown a~faster implementation using their Fibonacci
472 heaps, which runs in time $\O(m+n\log n)$. This is $\O(m)$ whenever the density of the
473 input graph reaches $\Omega(\log n)$. This suggests that we could combine the algorithm with
474 another MST algorithm, which identifies a~part of the MST edges and contracts
475 them to increase the density of the graph. For example, if we perform several Bor\o{u}vka
476 steps and then run the Jarn\'\i{}k's algorithm, we find the MST in time $\O(m\log\log n)$.
477
478 Actually, there is a~much better choice of the algorithms to combine: use the
479 Jarn\'\i{}k's algorithm with a~Fibonacci heap multiple times, each time stopping it after a~while.
480 A~good choice of the stopping condition is to place a~limit on the size of the heap.
481 We start with an~arbitrary vertex, grow the tree as usually and once the heap gets too large,
482 we conserve the current tree and start with a~different vertex and an~empty heap. When this
483 process runs out of vertices, it has identified a~sub-forest of the MST, so we can
484 contract the edges of~this forest and iterate.
485
486 \algn{Iterated Jarn\'\i{}k; Fredman and Tarjan \cite{ft:fibonacci}}\id{itjar}%
487 \algo
488 \algin A~graph~$G$ with an edge comparison oracle.
489 \:$T\=\emptyset$. \cmt{edges of the MST}
490 \:$\ell(e)\=e$ for all edges~$e$. \cmt{edge labels as usually}
491 \:$m_0\=m$.
492 \:While $n>1$: \cmt{We will call iterations of this loop \df{phases}.}
493 \::$F\=\emptyset$. \cmt{forest built in the current phase}
494 \::$t\=2^{\lceil 2m_0/n \rceil}$. \cmt{the limit on heap size}
495 \::While there is a~vertex $v_0\not\in F$:
496 \:::Run the Jarn\'\i{}k's algorithm from~$v_0$, stop when:
497 \::::all vertices have been processed, or
498 \::::a~vertex of~$F$ has been added to the tree, or
499 \::::the heap has grown to more than~$t$ elements.
500 \:::Denote the resulting tree~$R$.
501 \:::$F\=F\cup R$.
502 \::$T\=T\cup \ell[F]$. \cmt{Remember MST edges found in this phase.}
503 \::Contract all edges of~$F$ and flatten~$G$.
504 \algout Minimum spanning tree~$T$.
505 \endalgo
506
507 \thm\id{itjarthm}%
508 The Iterated Jarn\'\i{}k's algorithm finds the MST of the input graph in time
509 $\O(m\timesbeta(m,n))$, where $\beta(m,n):=\min\{ i \mid \log^{(i)}n \le m/n \}$.
510
511 \cor
512 The Iterated Jarn\'\i{}k's algorithm runs in time $\O(m\log^* n)$.
513
514 \paran{Integer weights}%
515 The algorithm spends most of the time in phases which have small heaps. Once the
516 heap grows to $\Omega(\log^{(k)} n)$ for any fixed~$k$, the graph gets dense enough
517 to guarantee that at most~$k$ phases remain. This means that if we are able to
518 construct a~heap of size $\Omega(\log^{(k)} n)$ with constant time per operation,
519 we can get a~linear-time algorithm for MST. This is the case when the weights are
520 integers (we can use the Q-heap trees from Section~\ref{ramds}.
521
522 \thmn{MST for integer weights, Fredman and Willard \cite{fw:transdich}}\id{intmst}%
523 MST of a~graph with integer edge weights can be found in time $\O(m)$ on the Word-RAM.
524
525 \section{Verification of minimality}\id{verifysect}%
526
527 Now we will turn our attention to a~slightly different problem: given a~spanning
528 tree, how to verify that it is minimum? We will show that this can be achieved
529 in linear time and it will serve as a~basis for a~randomized linear-time
530 MST algorithm in the next section.
531
532 MST verification has been studied by Koml\'os \cite{komlos:verify}, who has
533 proven that $\O(m)$ edge comparisons are sufficient, but his algorithm needed
534 super-linear time to find the edges to compare. Dixon, Rauch and Tarjan \cite{dixon:verify}
535 have later shown that the overhead can be reduced
536 to linear time on the RAM using preprocessing and table lookup on small
537 subtrees. Later, King has given a~simpler algorithm in \cite{king:verifytwo}.
538
539 To verify that a~spanning tree~$T$ is minimum, it is sufficient to check that all
540 edges outside~$T$ are $T$-heavy. For each edge $uv\in E\setminus T$, we will
541 find the heaviest edge of the tree path $T[u,v]$ (we will call it the \df{peak}
542 of the path) and compare its weight to $w(uv)$. We have therefore transformed
543 the MST verification to the problem of finding peaks for a~set of \df{query
544 paths} on a~given tree. By a~sequence of further transformations, we can even
545 assume that the given tree is \df{complete branching} (all vertices are on
546 the same level and internal vertices always have outdegree~2) and that the
547 query paths join a~vertex with one of its ancestors.
548
549 Koml\'os has given a~simple algorithm that traverses the complete branching
550 tree recursively. At each moment, it maintains an~array of peaks of the restrictions
551 of the query paths to the subtree below the current vertex. If we account for the
552 comparisons performed by this algorithm carefully and express the bound in terms
553 of the size of the original problem (before all the transformations), we get:
554
555 \thmn{Verification of the MST, Koml\'os \cite{komlos:verify}}\id{verify}%
556 For every weighted graph~$G$ and its spanning tree~$T$, it is sufficient to
557 perform $\O(m)$ comparisons of edge weights to determine whether~$T$ is minimum
558 and to find all $T$-light edges in~$G$.
559
560 It remains to demonstrate that the overhead of the algorithm needed to find
561 the required comparisons and infer the peaks from their results can be decreased,
562 so that it gets bounded by the number of comparisons and therefore also by $\O(m)$.
563 We will follow the idea of King from \cite{king:verifytwo}, but as we have the power
564 of the RAM data structures from Section~\ref{ramds} at our command, the low-level
565 details will be easier. Still, the construction is rather technical, so we omit
566 it in this abstract and state only the final theorem:
567
568 \thmn{Verification of MST on the RAM}\id{ramverify}%
569 There is a~RAM algorithm which for every weighted graph~$G$ and its spanning tree~$T$
570 determines whether~$T$ is minimum and finds all $T$-light edges in~$G$ in time $\O(m)$.
571
572 \rem
573 Buchsbaum et al.~\cite{buchsbaum:verify} have recently shown that linear-time
574 verification can be achieved even on the Pointer Machine.
575 They combine an~algorithm of time complexity $\O(m\timesalpha(m,n))$
576 based on the Disjoint Set Union data structure with the framework of topological graph
577 computations described in Section \ref{bucketsort}.
578 The online version of this problem has turned out to be more difficult: there
579 is a~super-linear lower bound for it due to Pettie \cite{pettie:onlineverify}.
580
581 \section{A randomized algorithm}\id{randmst}%
582
583 When we analysed the Contractive Bor\o{u}vka's algorithm in Section~\ref{contalg},
584 we observed that while the number of vertices per iteration decreases exponentially,
585 the number of edges generally does not, so we spend $\Theta(m)$ time on every phase.
586 Karger, Klein and Tarjan \cite{karger:randomized} have overcome this problem by
587 combining the Bor\o{u}vka's algorithm with filtering based on random sampling.
588 This leads to a~randomized algorithm which runs in linear expected time.
589
590 The principle of the filtering is simple: Let us consider any spanning tree~$T$
591 of the input graph~$G$. Each edge of~$G$ that is $T$-heavy is the heaviest edge
592 of some cycle, so by the Red lemma it cannot participate in
593 the MST of~$G$. We can therefore discard all $T$-heavy edges and continue with
594 finding the MST on the reduced graph. Of course, not all choices of~$T$ are equally
595 good, but it will soon turn out that when we take~$T$ as the MST of a~randomly selected
596 subgraph, only a~small expected number of edges remains:
597
598 \lemman{Random sampling, Karger \cite{karger:sampling}}\id{samplemma}%
599 Let $H$~be a~subgraph of~$G$ obtained by including each edge independently
600 with probability~$p$. Let further $F$~be the minimum spanning forest of~$H$. Then the
601 expected number of $F$-nonheavy\foot{That is, $F$-light edges and also edges of~$F$ itself.}
602 edges in~$G$ is at most $n/p$.
603
604 \para
605 We will formulate the algorithm as a~doubly-recursive procedure. It alternatively
606 performs steps of the Bor\o{u}vka's algorithm and filtering based on the above lemma.
607 The first recursive call computes the MSF of the sampled subgraph, the second one
608 finds the MSF of the original graph, but without the heavy edges.
609
610 \algn{MSF by random sampling --- the KKT algorithm}\id{kkt}%
611 \algo
612 \algin A~graph $G$ with an~edge comparison oracle.
613 \:Remove isolated vertices from~$G$. If no vertices remain, stop and return an~empty forest.
614 \:Perform two Bor\o{u}vka steps (iterations of Algorithm \ref{contbor}) on~$G$ and
615   remember the set~$B$ of the edges having been contracted.
616 \:Select a~subgraph~$H\subseteq G$ by including each edge independently with
617   probability $1/2$.
618 \:$F\=\msf(H)$ calculated recursively.
619 \:Construct $G'\subseteq G$ by removing all $F$-heavy edges of~$G$.
620 \:$R\=\msf(G')$ calculated recursively.
621 \:Return $R\cup B$.
622 \algout The minimum spanning forest of~$G$.
623 \endalgo
624
625 A~careful analysis of this algorithm, based on properties of its recursion tree
626 and the peak-finding algorithm of the previous section yields the following time bounds:
627
628 \thm
629 The KKT algorithm runs in time $\O(\min(n^2,m\log n))$ in the worst case on the RAM.
630
631 \thm
632 The expected time complexity of the KKT algorithm on the RAM is $\O(m)$.
633
634 \chapter{Approaching Optimality}\id{optchap}%
635
636 \section{Soft heaps}\id{shsect}%
637
638 A~vast majority of MST algorithms that we have encountered so far is based on
639 the Tarjan's Blue rule (Lemma \ref{bluelemma}). The rule serves to identify
640 edges that belong to the MST, while all other edges are left in the process. This
641 unfortunately means that the later stages of computation spend most of
642 their time on these edges that never enter the MSF. A~notable exception is the randomized
643 algorithm of Karger, Klein and Tarjan. It adds an~important ingredient: it uses
644 the Red rule (Lemma \ref{redlemma}) to filter out edges that are guaranteed to stay
645 outside the MST, so that the graphs with which the algorithm works get smaller
646 with time.
647
648 Recently, Chazelle \cite{chazelle:ackermann} and Pettie \cite{pettie:ackermann}
649 have presented new deterministic algorithms for the MST which are also based
650 on the combination of both rules. They have reached worst-case time complexity
651 $\O(m\timesalpha(m,n))$ on the Pointer Machine. We will devote this chapter to their results
652 and especially to another algorithm by Pettie and Ramachandran \cite{pettie:optimal}
653 which is provably optimal.
654
655 At the very heart of all these algorithms lies the \df{soft heap} discovered by
656 Chazelle \cite{chazelle:softheap}. It is a~meldable priority queue, roughly
657 similar to the Vuillemin's binomial heaps \cite{vuillemin:binheap} or Fredman's
658 and Tarjan's Fibonacci heaps \cite{ft:fibonacci}. The soft heaps run faster at
659 the expense of \df{corrupting} a~fraction of the inserted elements by raising
660 their values (the values are however never lowered). This allows for
661 a~trade-off between accuracy and speed, controlled by a~parameter~$\varepsilon$.
662 The heap operations take $\O(\log(1/\varepsilon))$ amortized time and at every
663 moment at most~$\varepsilon n$ elements of the $n$~elements inserted can be
664 corrupted.
665
666 \defnn{Soft heap interface}%
667 The \df{soft heap} contains a~set of distinct items from a~totally ordered universe and it
668 supports the following operations:
669 \itemize\ibull
670 \:$\<Create>(\varepsilon)$ --- Create an~empty soft heap with the given accuracy parameter~$\varepsilon$.
671 \:$\<Insert>(H,x)$ --- Insert a~new item~$x$ into the heap~$H$.
672 \:$\<Meld>(P,Q)$ --- Merge two heaps into one, more precisely move all items of a~heap~$Q$
673   to the heap~$P$, destroying~$Q$ in the process. Both heaps must have the same~$\varepsilon$.
674 \:$\<DeleteMin>(H)$ --- Delete the minimum item of the heap~$H$ and return its value
675   (optionally signalling that the value has been corrupted).
676 \:$\<Explode>(H)$ --- Destroy the heap and return a~list of all items contained in it
677   (again optionally marking those corrupted).
678 \endlist
679
680 \>We describe the exact mechanics of the soft heaps and analyse its complexity.
681 The important properties are summarized in the following theorem:
682
683 \thmn{Performance of soft heaps, Chazelle \cite{chazelle:softheap}}\id{softheap}%
684 A~soft heap with error rate~$\varepsilon$ ($0<\varepsilon\le 1/2$) processes
685 a~sequence of operations starting with an~empty heap and containing $n$~\<Insert>s
686 in time $\O(n\log(1/\varepsilon))$ on the Pointer Machine. At every moment, the
687 heap contains at most $\varepsilon n$ corrupted items.
688
689 \section{Robust contractions}
690
691 Having the soft heaps at hand, we would like to use them in a~conventional MST
692 algorithm in place of a~normal heap. The most efficient specimen of a~heap-based
693 algorithm we have seen so far is the Jarn\'\i{}k's algorithm.
694 We can try implanting the soft heap in this algorithm, preferably in the earlier
695 version without Fibonacci heaps as the soft heap lacks the \<Decrease> operation.
696 This brave, but somewhat simple-minded attempt is however doomed to
697 fail. The reason is of course the corruption of items inside the heap, which
698 leads to increase of weights of some subset of edges. In presence of corrupted
699 edges, most of the theory we have so carefully built breaks down. There is
700 fortunately some light in this darkness. While the basic structural properties
701 of MST's no longer hold, there is a~weaker form of the Contraction lemma that
702 takes the corrupted edges into account. Before we prove this lemma, we expand
703 our awareness of subgraphs which can be contracted.
704
705 \defn
706 A~subgraph $C\subseteq G$ is \df{contractible} iff for every pair of edges $e,f\in\delta(C)$\foot{That is,
707 of~$G$'s edges with exactly one endpoint in~$C$.} there exists a~path in~$C$ connecting the endpoints
708 of the edges $e,f$ such that all edges on this path are lighter than either $e$ or~$f$.
709
710 For example, when we stop the Jarn\'\i{}k's algorithm at some moment and
711 we take a~subgraph~$C$ induced by the constructed tree, this subgraph is contractible.
712 We can now easily reformulate the Contraction lemma (\ref{contlemma}) in the language
713 of contractible subgraphs:
714
715 \lemman{Generalized contraction}
716 When~$C\subseteq G$ is a~contractible subgraph, then $\msf(G)=\msf(C) \cup \msf(G/C)$.
717
718 We can now bring corruption back to the game and state a~``robust'' version
719 of this lemma. A~notation for corrupted graphs will be handy:
720
721 \nota\id{corrnota}%
722 When~$G$ is a~weighted graph and~$R$ a~subset of its edges, we will use $G\crpt
723 R$ to denote an arbitrary graph obtained from~$G$ by increasing the weights of
724 some of the edges in~$R$.
725 Whenever~$C$ is a~subgraph of~$G$, we will use $R^C$ to refer to the edges of~$R$ with
726 exactly one endpoint in~$C$ (i.e., $R^C = R\cap \delta(C)$).
727
728 \lemman{Robust contraction, Chazelle \cite{chazelle:almostacker}}\id{robcont}%
729 Let $G$ be a~weighted graph and $C$~its subgraph contractible in~$G\crpt R$
730 for some set~$R$ of edges. Then $\msf(G) \subseteq \msf(C) \cup \msf((G/C) \setminus R^C) \cup R^C$.
731
732 \para
733 We will mimic the Iterated Jarn\'\i{}k's algorithm. We will partition the given graph to a~collection~$\C$
734 of non-overlapping contractible subgraphs called \df{clusters} and we put aside all edges that got corrupted in the process.
735 We recursively compute the MSF of those subgraphs and of the contracted graph. Then we take the
736 union of these MSF's and add the corrupted edges. According to the previous lemma, this does not produce
737 the MSF of~$G$, but a~sparser graph containing it, on which we can continue.
738
739 \thmn{Partitioning to contractible clusters, Chazelle \cite{chazelle:almostacker}}\id{partthm}%
740 Given a~weighted graph~$G$ and parameters $\varepsilon$ ($0<\varepsilon\le 1/2$)
741 and~$t$, we can construct a~collection $\C=\{C_1,\ldots,C_k\}$ of clusters and a~set~$R^\C$ of edges such that:
742
743 \numlist\ndotted
744 \:All the clusters and the set~$R^\C$ are mutually edge-disjoint.
745 \:Each cluster contains at most~$t$ vertices.
746 \:Each vertex of~$G$ is contained in at least one cluster.
747 \:The connected components of the union of all clusters have at least~$t$ vertices each,
748   except perhaps for those which are equal to a~connected component of $G\setminus R^\C$.
749 \:$\vert R^\C\vert \le 2\varepsilon m$.
750 \:$\msf(G) \subseteq \bigcup_i \msf(C_i) \cup \msf\bigl((G / \bigcup_i C_i) \setminus R^\C\bigr) \cup R^\C$.
751 \:The construction takes $\O(n+m\log (1/\varepsilon))$ time.
752 \endlist
753
754 \section{Decision trees}\id{dtsect}%
755
756 The Pettie's and Ramachandran's algorithm combines the idea of robust partitioning with optimal decision
757 trees constructed by brute force for very small subgraphs.
758 Formally, the decision trees are defined as follows:
759
760 \defnn{Decision trees and their complexity}\id{decdef}%
761 A~\df{MSF decision tree} for a~graph~$G$ is a~binary tree. Its internal vertices
762 are labeled with pairs of $G$'s edges to be compared, each of the two outgoing tree edges
763 corresponds to one possible result of the comparison.
764 Leaves of the tree are labeled with spanning trees of the graph~$G$.
765
766 A~\df{computation} of the decision tree on a~specific permutation of edge weights
767 in~$G$ is the path from the root to a~leaf such that the outcome of every comparison
768 agrees with the edge weights. The result of the computation is the spanning tree
769 assigned to its final leaf.
770 A~decision tree is \df{correct} iff for every permutation the corresponding
771 computation results in the real MSF of~$G$ with the particular weights.
772
773 The \df{time complexity} of a~decision tree is defined as its depth. It therefore
774 bounds the number of comparisons spent on every path. (It need not be equal since
775 some paths need not correspond to an~actual computation --- the sequence of outcomes
776 on the path could be unsatisfiable.)
777
778 A~decision tree is called \df{optimal} if it is correct and its depth is minimum possible
779 among the correct decision trees for the given graph.
780 We will denote an~arbitrary optimal decision tree for~$G$ by~${\cal D}(G)$ and its
781 complexity by~$D(G)$.
782
783 The \df{decision tree complexity} $D(m,n)$ of the MSF problem is the maximum of~$D(G)$
784 over all graphs~$G$ with $n$~vertices and~$m$ edges.
785
786 \obs
787 Decision trees are the most general deterministic comparison-based computation model possible.
788 The only operations that count in its time complexity are comparisons. All
789 other computation is free, including solving NP-complete problems or having
790 access to an~unlimited source of non-uniform constants. The decision tree
791 complexity is therefore an~obvious lower bound on the time complexity of the
792 problem in all other comparison-based models.
793
794 The downside is that we do not know any explicit construction of the optimal
795 decision trees, or at least a~non-constructive proof of their complexity.
796 On the other hand, the complexity of any existing comparison-based algorithm
797 can be used as an~upper bound on the decision tree complexity. Also, we can
798 construct an~optimal decision tree using brute force:
799
800 \lemma
801 An~optimal MST decision tree for a~graph~$G$ on~$n$ vertices can be constructed on
802 the Pointer Machine in time $\O(2^{2^{4n^2}})$.
803
804 \section{An optimal algorithm}\id{optalgsect}%
805
806 Once we have developed the soft heaps, partitioning and MST decision trees,
807 it is now simple to state the Pettie's and Ramachandran's MST algorithm
808 and prove that it is asymptotically optimal among all MST algorithms in
809 comparison-based models. Several standard MST algorithms from the previous
810 chapters will also play their roles.
811
812 We will describe the algorithm as a~recursive procedure. When the procedure is
813 called on a~graph~$G$, it sets the parameter~$t$ to roughly $\log^{(3)} n$ and
814 it calls the \<Partition> procedure to split the graph into a~collection of
815 clusters of size~$t$ and a~set of corrupted edges. Then it uses precomputed decision
816 trees to find the MSF of the clusters. The graph obtained by contracting
817 the clusters is on the other hand dense enough, so that the Iterated Jarn\'\i{}k's
818 algorithm runs on it in linear time. Afterwards we combine the MSF's of the clusters
819 and of the contracted graphs, we mix in the corrupted edges and run two iterations
820 of the Contractive Bor\o{u}vka's algorithm. This guarantees reduction in the number of
821 both vertices and edges by a~constant factor, so we can efficiently recurse on the
822 resulting graph.
823
824 \algn{Optimal MST algorithm, Pettie and Ramachandran \cite{pettie:optimal}}\id{optimal}%
825 \algo
826 \algin A~connected graph~$G$ with an~edge comparison oracle.
827 \:If $G$ has no edges, return an~empty tree.
828 \:$t\=\lfloor\log^{(3)} n\rfloor$. \cmt{the size of clusters}
829 \:Call the partitioning procedure (\ref{partthm}) on $G$ and $t$ with $\varepsilon=1/8$. It returns
830   a~collection~$\C=\{C_1,\ldots,C_k\}$ of clusters and a~set~$R^\C$ of corrupted edges.
831 \:$F_i \= \mst(C_i)$ for all~$i$, obtained using optimal decision trees.
832 \:$G_A \= (G / \bigcup_i C_i) \setminus R^\C$. \cmt{the contracted graph}
833 \:$F_A \= \msf(G_A)$ calculated by the Iterated Jarn\'\i{}k's algorithm (\ref{itjar}).
834 \:$G_B \= \bigcup_i F_i \cup F_A \cup R^\C$. \cmt{combine subtrees with corrupted edges}
835 \:Run two Bor\o{u}vka steps (iterations of the Contractive Bor\o{u}vka's algorithm, \ref{contbor}) on~$G_B$,
836   getting a~contracted graph~$G_C$ and a~set~$F_B$ of MST edges.
837 \:$F_C \= \mst(G_C)$ obtained by a~recursive call to this algorithm.
838 \:Return $F_B \cup F_C$.
839 \algout The minimum spanning tree of~$G$.
840 \endalgo
841
842 Correctness of this algorithm immediately follows from the Partitioning theorem (\ref{partthm})
843 and from the proofs of the respective algorithms used as subroutines. As for time complexity:
844
845 \lemma\id{optlemma}%
846 The time complexity $T(m,n)$ of the Optimal algorithm satisfies the following recurrence:
847 $$
848 T(m,n) \le \sum_i c_1 D(C_i) + T(m/2, n/4) + c_2 m,
849 $$
850 where~$c_1$ and~$c_2$ are some positive constants and $D$~is the decision tree complexity
851 from the previous section.
852
853 It turns out that the recurrence is satisfied by the decision tree complexity function
854 $D(m,n)$ itself, so we can prove the following theorem by induction:
855
856 \thm
857 The time complexity of the Optimal algorithm is $\Theta(D(m,n))$.
858
859 \paran{Complexity of MST}%
860 As we have already noted, the exact decision tree complexity $D(m,n)$ of the MST problem
861 is still open and so therefore is the time complexity of the optimal algorithm. However,
862 every time we come up with another comparison-based algorithm, we can use its complexity
863 (or more specifically the number of comparisons it performs, which can be even lower)
864 as an~upper bound on the optimal algorithm.
865 The best explicit comparison-based algorithm known to date has been discovered by Chazelle
866 \cite{chazelle:ackermann} and independently by Pettie \cite{pettie:ackermann}. It achieves complexity $\O(m\timesalpha(m,n))$.
867 Using any of these results, we can prove an~Ackermannian upper bound on the
868 optimal algorithm:
869
870 \thm
871 The time complexity of the Optimal algorithm is $\O(m\timesalpha(m,n))$.
872
873 \chapter{Dynamic Spanning Trees}\id{dynchap}%
874
875 \section{Dynamic graph algorithms}
876
877 In many applications, we often need to solve a~certain graph problem for a~sequence of graphs that
878 differ only a~little, so recomputing the solution for every graph from scratch would be a~waste of
879 time. In such cases, we usually turn our attention to \df{dynamic graph algorithms.} A~dynamic
880 algorithm is in fact a~data structure that remembers a~graph. It offers operations that modify the
881 structure of the graph and also operations that query the result of the problem for the current
882 state of the graph. A~typical example of a~problem of this kind is dynamic maintenance of connected
883 components:
884
885 \problemn{Dynamic connectivity}
886 Maintain an~undirected graph under a~sequence of the following operations:
887 \itemize\ibull
888 \:$\<Init>(n)$ --- Create a~graph with $n$~isolated vertices $\{1,\ldots,n\}$.\foot{%
889 The structure could support dynamic addition and removal of vertices, too,
890 but this is easy to add and infrequently used, so we will rather keep the set
891 of vertices fixed for clarity.}
892 \:$\<Insert>(G,u,v)$ --- Insert an~edge $uv$ to~$G$ and return its unique
893 identifier. This assumes that the edge did not exist yet.
894 \:$\<Delete>(G,e)$ --- Delete an~edge specified by its identifier from~$G$.
895 \:$\<Connected>(G,u,v)$ --- Test if vertices $u$ and~$v$ are in the same connected component of~$G$.
896 \endlist
897
898 In this chapter, we will focus on the dynamic version of the minimum spanning forest.
899 This problem seems to be intimately related to the dynamic connectivity. Indeed, all known
900 algorithms for dynamic connectivity maintain some sort of a~spanning forest.
901 This suggests that a~dynamic MSF algorithm could be obtained by modifying the
902 mechanics of the data structure to keep the forest minimum.
903 We however have to answer one important question first: What should be the output of
904 our MSF data structure? Adding an~operation that returns the MSF of the current
905 graph would be of course possible, but somewhat impractical as this operation would have to
906 spend $\Omega(n)$ time on the mere writing of its output. A~better way seems to
907 be making the \<Insert> and \<Delete> operations report the list of modifications
908 of the MSF implied by the change in the graph. It is easy to prove that $\O(1)$
909 modifications always suffice, so we can formulate our problem as follows:
910
911 \problemn{Dynamic minimum spanning forest}
912 Maintain an~undirected graph with distinct weights on edges (drawn from a~totally ordered set)
913 and its minimum spanning forest under a~sequence of the following operations:
914 \itemize\ibull
915 \:$\<Init>(n)$ --- Create a~graph with $n$~isolated vertices $\{1,\ldots,n\}$.
916 \:$\<Insert>(G,u,v,w)$ --- Insert an~edge $uv$ of weight~$w$ to~$G$. Return its unique
917         identifier and the list of additions and deletions of edges in $\msf(G)$.
918 \:$\<Delete>(G,e)$ --- Delete an~edge specified by its identifier from~$G$.
919         Return the list of additions and deletions of edges in $\msf(G)$.
920 \endlist
921
922 \paran{Incremental MSF}%
923 In case only edge insertions are allowed, the problem reduces to finding the heaviest
924 edge (peak) on the tree path covered by the newly inserted edge and replacing the peak
925 if needed. This can be handled quite efficiently by using the Link-Cut trees of Sleator
926 and Tarjan \cite{sleator:trees}. We obtain logarithmic time bound:
927
928 \thmn{Incremental MSF}
929 When only edge insertions are allowed, the dynamic MSF can be maintained in time $\O(\log n)$
930 amortized per operation.
931
932 \section{Dynamic connectivity}
933
934 The fully dynamic connectivity problem has a~long and rich history. In the 1980's, Frederickson \cite{frederickson:dynamic}
935 has used his topological trees to construct a~dynamic connectivity algorithm of complexity $\O(\sqrt m)$ per update and
936 $\O(1)$ per query. Eppstein et al.~\cite{eppstein:sparsify} have introduced a~sparsification technique which can bring the
937 updates down to $\O(\sqrt n)$. Later, several different algorithms with complexity on the order of $n^\varepsilon$
938 were presented by Henzinger and King \cite{henzinger:mst} and also by Mare\v{s} \cite{mares:dga}.
939 A~polylogarithmic time bound was first reached by the randomized algorithm of Henzinger and King \cite{henzinger:randdyn}.
940 The best result known as of now is the $\O(\log^2 n)$ time deterministic algorithm by Holm,
941 de~Lichtenberg and Thorup \cite{holm:polylog}, which will we describe in this section.
942
943 The algorithm will maintain a~spanning forest~$F$ of the current graph~$G$, represented by an~ET-tree
944 which will be used to answer connectivity queries. The edges of~$G\setminus F$ will be stored as~non-tree
945 edges in the ET-tree. Hence, an~insertion of an~edge to~$G$ either adds it to~$F$ or inserts it as non-tree.
946 Deletions of non-tree edges are also easy, but when a~tree edge is deleted, we have to search for its
947 replacement among the non-tree edges.
948
949 To govern the search in an~efficient way, we will associate each edge~$e$ with a~level $\ell(e) \le
950 L = \lfloor\log_2 n\rfloor$. For each level~$i$, we will use~$F_i$ to denote the subforest
951 of~$F$ containing edges of level at least~$i$. Therefore $F=F_0 \supseteq F_1 \supseteq \ldots \supseteq F_L$.
952 We will maintain the following \em{invariants:}
953
954 {\narrower
955 \def\iinv{{\bo I\the\itemcount~}}
956 \numlist\iinv
957 \:$F$~is the maximum spanning forest of~$G$ with respect to the levels. (In other words,
958 if $uv$ is a~non-tree edge, then $u$ and~$v$ are connected in~$F_{\ell(uv)}$.)
959 \:For each~$i$, the components of~$F_i$ have at most $\lfloor n/2^i \rfloor$ vertices each.
960 (This implies that it does not make sense to define~$F_i$ for $i>L$, because it would be empty
961 anyway.)
962 \endlist
963 }
964
965 At the beginning, the graph contains no edges, so both invariants are trivially
966 satisfied. Newly inserted edges enter level~0, which cannot break I1 nor~I2.
967
968 When we delete a~tree edge at level~$\ell$, we split a~tree~$T$ of~$F_\ell$ to two
969 trees $T_1$ and~$T_2$. Without loss of generality, let us assume that $T_1$ is the
970 smaller one. We will try to find the replacement edge of the highest possible
971 level that connects the spanning tree back. From I1, we know that such an~edge cannot belong to
972 a~level greater than~$\ell$, so we start looking for it at level~$\ell$. According
973 to~I2, the tree~$T$ had at most $\lfloor n/2^\ell\rfloor$ vertices, so $T_1$ has
974 at most $\lfloor n/2^{\ell+1} \rfloor$ of them. Thus we can move all level~$\ell$
975 edges of~$T_1$ to level~$\ell+1$ without violating either invariant.
976
977 We now start enumerating the non-tree edges incident with~$T_1$. Each such edge
978 is either local to~$T_1$ or it joins $T_1$ with~$T_2$. We will therefore check each edge
979 whether its other endpoint lies in~$T_2$ and if it does, we have found the replacement
980 edge, so we insert it to~$F_\ell$ and stop. Otherwise we move the edge one level up. (This
981 will be the grist for the mill of our amortization argument: We can charge most of the work on level
982 increases and we know that the level of each edge can reach at most~$L$.)
983
984 If the non-tree edges at level~$\ell$ are exhausted, we try the same in the next
985 lower level and so on. If there is no replacement edge at level~0, the tree~$T$
986 remains disconnected.
987
988 The implementation uses the Eulerian Tour trees of Henzinger and King \cite{henzinger:randdyn}
989 to represent the forests~$F_\ell$ together with the non-tree edges at each particular level.
990 A~simple amortized analysis using the levels yields the following result:
991
992 \thmn{Fully dynamic connectivity, Holm et al.~\cite{holm:polylog}}\id{dyncon}%
993 Dynamic connectivity can be maintained in time $\O(\log^2 n)$ amortized per
994 \<Insert> and \<Delete> and in time $\O(\log n/\log\log n)$ per \<Connected>
995 in the worst case.
996
997 \rem\id{dclower}%
998 An~$\Omega(\log n/\log\log n)$ lower bound for the amortized complexity of the dynamic connectivity
999 problem has been proven by Henzinger and Fredman \cite{henzinger:lowerbounds} in the cell
1000 probe model with $\O(\log n)$-bit words. Thorup has answered by a~faster algorithm
1001 \cite{thorup:nearopt} that achieves $\O(\log n\log^3\log n)$ time per update and
1002 $\O(\log n/\log^{(3)} n)$ per query on a~RAM with $\O(\log n)$-bit words. (He claims
1003 that the algorithm runs on a~Pointer Machine, but it uses arithmetic operations,
1004 so it does not fit the definition of the PM we use. The algorithm only does not
1005 need direct indexing of arrays.) So far, it is not known how to extend this algorithm
1006 to fit our needs, so we omit the details.
1007
1008 \section{Dynamic spanning forests}\id{dynmstsect}%
1009
1010 Let us turn our attention back to the dynamic MSF.
1011 Most of the early algorithms for dynamic connectivity also imply $\O(n^\varepsilon)$
1012 algorithms for dynamic maintenance of the MSF. Henzinger and King \cite{henzinger:twoec,henzinger:randdyn}
1013 have generalized their randomized connectivity algorithm to maintain the MSF in $\O(\log^5 n)$ time per
1014 operation, or $\O(k\log^3 n)$ if only $k$ different values of edge weights are allowed. They have solved
1015 the decremental version of the problem first (which starts with a~given graph and only edge deletions
1016 are allowed) and then presented a~general reduction from the fully dynamic MSF to its decremental version.
1017 We will describe the algorithm of Holm, de Lichtenberg and Thorup \cite{holm:polylog}, who have followed
1018 the same path. They have modified their dynamic connectivity algorithm to solve the decremental MSF
1019 in $\O(\log^2 n)$ and obtained the fully dynamic MSF working in $\O(\log^4 n)$ per operation.
1020
1021 \paran{Decremental MSF}%
1022 Turning the algorithm from the previous section to the decremental MSF requires only two
1023 changes: First, we have to start with the forest~$F$ equal to the MSF of the initial
1024 graph. As we require to pay $\O(\log^2 n)$ for every insertion, we can use almost arbitrary
1025 MSF algorithm to find~$F$. Second, when we search for an~replacement edge, we need to pick
1026 the lightest possible choice. We will therefore use a~weighted version of the ET-trees.
1027 We must ensure that the lower levels cannot contain a~lighter replacement edge,
1028 but fortunately the light edges tend to ``bubble up'' in the hierarchy of
1029 levels. This can be formalized in form of the following invariant:
1030
1031 {\narrower
1032 \def\iinv{{\bo I\the\itemcount~}}
1033 \numlist\iinv
1034 \itemcount=2
1035 \:On every cycle, the heaviest edge has the smallest level.
1036 \endlist
1037 }
1038
1039 \>This immediately implies that we always select the right replacement edge:
1040
1041 \lemma\id{msfrepl}%
1042 Let $F$~be the minimum spanning forest and $e$ any its edge. Then among all replacement
1043 edges for~$e$, the lightest one is at the maximum level.
1044
1045 A~brief analysis also shows that the invariant I3 is observed by all operations
1046 on the structure. We can conclude:
1047
1048 \thmn{Decremental MSF, Holm et al.~\cite{holm:polylog}}
1049 When we start with a~graph on $n$~vertices with~$m$ edges and we perform a~sequence of
1050 edge deletions, the MSF can be initialized in time $\O((m+n)\cdot\log^2 n)$ and then
1051 updated in time $\O(\log^2 n)$ amortized per operation.
1052
1053 \paran{Fully dynamic MSF}%
1054 The decremental MSF algorithm can be turned to a~fully dynamic one by a~blackbox
1055 reduction whose properties are summarized in the following theorem:
1056
1057 \thmn{MSF dynamization, Holm et al.~\cite{holm:polylog}}
1058 Suppose that we have a~decremental MSF algorithm with the following properties:
1059 \numlist\ndotted
1060 \:For any $a$,~$b$, it can be initialized on a~graph with~$a$ vertices and~$b$ edges.
1061 \:Then it executes an~arbitrary sequence of deletions in time $\O(b\cdot t(a,b))$, where~$t$ is a~non-decreasing function.
1062 \endlist
1063 \>Then there exists a~fully dynamic MSF algorithm for a~graph on $n$~vertices, starting
1064 with no edges, that performs $m$~insertions and deletions in amortized time:
1065 $$
1066 \O\left( \log^3 n + \sum_{i=1}^{\log m} \sum_{j=1}^i \; t(\min(n,2^j), 2^j) \right) \hbox{\quad per operation.}
1067 $$
1068
1069 \corn{Fully dynamic MSF}\id{dynmsfcorr}%
1070 There is a~fully dynamic MSF algorithm that works in time $\O(\log^4 n)$ amortized
1071 per operation for graphs on $n$~vertices.
1072
1073 \paran{Dynamic MSF with limited edge weights}%
1074 If the set from which the edge weights are drawn is small, we can take a~different
1075 approach. If only two values are allowed, we split the graph to subgraphs $G_1$ and~$G_2$
1076 induced by the edges of the respective weights and we maintain separate connectivity
1077 structures (together with a~spanning tree) for $G_1$ and $G_2 \cup T_1$ (where $T_1$
1078 is a~spanning tree of~$G_1$). We can easily modify the structure for $G_2\cup
1079 T_1$ to prefer the edges of~$T_1$. This ensures that the spanning tree of $G_2\cup T_1$
1080 will be the MST of the whole~$G$.
1081
1082 If there are more possible values, we simply iterate this construction: the $i$-th
1083 structure contains edges of weight~$i$ and the edges of the spanning tree from the
1084 $(i-1)$-th structure. We get:
1085
1086 \thmn{MSF with limited edge weights}
1087 There is a~fully dynamic MSF algorithm that works in time $\O(k\cdot\log^2 n)$ amortized
1088 per operation for graphs on $n$~vertices with only $k$~distinct edge weights allowed.
1089
1090 \section{Almost minimum trees}\id{kbestsect}%
1091
1092 In some situations, finding the single minimum spanning tree is not enough and we are interested
1093 in the $K$~lightest spanning trees, usually for some small value of~$K$. Katoh, Ibaraki
1094 and Mine \cite{katoh:kmin} have given an~algorithm of time complexity $\O(m\log\beta(m,n) + Km)$,
1095 building on the MST algorithm of Gabow et al.~\cite{gabow:mst}.
1096 Subsequently, Eppstein \cite{eppstein:ksmallest} has discovered an~elegant preprocessing step which allows to reduce
1097 the running time to $\O(m\log\beta(m,n) + \min(K^2,Km))$ by eliminating edges
1098 which are either present in all $K$ trees or in none of them.
1099 We will show a~variant of their algorithm based on the MST verification
1100 procedure of Section~\ref{verifysect}.
1101
1102 In this section, we will require the edge weights to be numeric, because
1103 comparisons are certainly not sufficient to determine the second best spanning tree. We will
1104 assume that our computation model is able to add, subtract and compare the edge weights
1105 in constant time.
1106
1107 Let us focus on finding the second lightest spanning tree first.
1108
1109 \paran{Second lightest spanning tree}%
1110 Suppose that we have a~weighted graph~$G$ and a~sequence $T_1,\ldots,T_z$ of all its spanning
1111 trees. Also suppose that the weights of these spanning trees are distinct and that the sequence
1112 is ordered by weight, i.e., $w(T_1) < \ldots < w(T_z)$ and $T_1 = \mst(G)$. Let us observe
1113 that each tree is similar to at least one of its predecessors:
1114
1115 \lemman{Difference lemma}\id{kbl}%
1116 For each $i>1$ there exists $j<i$ such that $T_i$ and~$T_j$ differ by a~single edge exchange.
1117
1118 \para
1119 This lemma implies that the second best spanning tree~$T_2$ differs from~$T_1$ by a~single
1120 edge exchange. It remains to find which exchange it is, but this can be reduced to finding
1121 peaks of the paths covered by the edges outside~$T_1$, which we already are able to solve
1122 efficiently by the methods of Section~\ref{verifysect}. Therefore:
1123
1124 \lemma
1125 For every graph~$H$ and a~MST $T$ of~$H$, linear time is sufficient to find
1126 edges $e\in T$ and $f\in H\setminus T$ such that $w(f)-w(e)$ is minimum.
1127
1128 \nota
1129 We will call this procedure \df{finding the best exchange in $(H,T)$.}
1130
1131 \cor
1132 Given~$G$ and~$T_1$, we can find~$T_2$ in time $\O(m)$.
1133
1134 \paran{Third lightest spanning tree}%
1135 Once we know~$T_1$ and~$T_2$, how to get~$T_3$? According to the Difference lemma, $T_3$~can be
1136 obtained by a~single exchange from either~$T_1$ or~$T_2$. Therefore we need to find the
1137 best exchange for~$T_2$ and the second best exchange for~$T_1$ and use the better of them.
1138 The latter is not easy to find directly, but we can get around it:
1139
1140 \obs\id{tbobs}%
1141 The tree $T_3$~can be obtained by a~single edge exchange in either $(G_1,T_1/e)$ or $(G_2,T_2)$:
1142
1143 \itemize\ibull
1144 \:If $T_3 = T_1-e'+f'$ for $e'\ne e$, then $T_3/e = (T_1/e)-e'+f'$ in~$G_1$.
1145 \:If $T_3 = T_1-e+f'$, then $T_3 = T_2 - f + f'$ in~$G_2$.
1146 \:If $T_3 = T_2-e'+f'$, then this exchange is found in~$G_2$.
1147 \endlist
1148
1149 \>Thus we can run the previous algorithm for finding the best edge exchange
1150 on both~$G_1$ and~$G_2$ and find~$T_3$ again in time $\O(m)$.
1151
1152 \paran{Further spanning trees}%
1153 The construction of auxiliary graphs can be iterated to obtain $T_1,\ldots,T_K$
1154 for an~arbitrary~$K$. We will build a~\df{meta-tree} of auxiliary graphs. Each node of this meta-tree
1155 carries a~graph\foot{This graph is always derived from~$G$ by a~sequence of edge deletions
1156 and contractions. It is tempting to say that it is a~minor of~$G$, but this is not true as we
1157 preserve multiple edges.} and its minimum spanning tree. The root node contains~$(G,T_1)$,
1158 its sons have $(G_1,T_1/e)$ and $(G_2,T_2)$. When $T_3$ is obtained by an~exchange
1159 in one of these sons, we attach two new leaves to that son and we let them carry the two auxiliary
1160 graphs derived by contracting or deleting the exchanged edge. Then we find the best
1161 edge exchanges among all leaves of the new meta-tree and repeat the process. By Observation \ref{tbobs},
1162 each spanning tree of~$G$ is generated exactly once. The Difference lemma guarantees that
1163 the trees are enumerated in the increasing order. So we get:
1164
1165 \lemma\id{kbestl}%
1166 Given~$G$ and~$T_1$, we can find $T_2,\ldots,T_K$ in time $\O(Km + K\log K)$.
1167
1168 \paran{Invariant edges}%
1169 Our algorithm can be further improved for small values of~$K$ (which seems to be the common
1170 case in most applications) by the reduction of Eppstein \cite{eppstein:ksmallest}.
1171 We will observe that there are many edges of~$T_1$
1172 which are guaranteed to be contained in $T_2,\ldots,T_K$ as well, and likewise there are
1173 many edges of $G\setminus T_1$ which are excluded from all those spanning trees.
1174 When we combine this with the previous construction, we get the following theorem:
1175
1176 \thmn{Finding $K$ lightest spanning trees}\id{kbestthm}%
1177 For a~given graph~$G$ with real edge weights and a~positive integer~$K$, the $K$~best spanning trees can be found
1178 in time $\O(m\timesalpha(m,n) + \min(K^2,Km + K\log K))$.
1179
1180 %--------------------------------------------------------------------------------
1181
1182 \chapter{Ranking Combinatorial Structures}\id{rankchap}%
1183
1184 \chapter{Bibliography}
1185
1186 \dumpbib
1187
1188 \vfill\eject
1189 \ifodd\pageno\else\hbox{}\fi
1190
1191 \bye