]> mj.ucw.cz Git - saga.git/blob - opt.tex
First part of corrections of bibliography.
[saga.git] / opt.tex
1 \ifx\endpart\undefined
2 \input macros.tex
3 \fi
4
5 \chapter{Approaching Optimality}\id{optchap}%
6
7 \section{Soft heaps}\id{shsect}%
8
9 A~vast majority of MST algorithms that we have encountered so far is based on
10 the Tarjan's Blue rule (Lemma \ref{bluelemma}). The rule serves to identify
11 edges that belong to the MST, while all other edges are left in the process. This
12 unfortunately means that the later stages of computation spend most of
13 their time on these edges that never enter the MSF. A~notable exception is the randomized
14 algorithm of Karger, Klein and Tarjan. It adds an~important ingredient: it uses
15 the Red rule (Lemma \ref{redlemma}) to filter out edges that are guaranteed to stay
16 outside the MST, so that the graphs with which the algorithm works get smaller
17 with time.
18
19 Recently, Chazelle \cite{chazelle:ackermann} and Pettie \cite{pettie:ackermann}
20 have presented new deterministic algorithms for the MST which are also based
21 on the combination of both rules. They have reached worst-case time complexity
22 $\O(m\timesalpha(m,n))$ on the Pointer Machine. We will devote this chapter to their results
23 and especially to another algorithm by Pettie and Ramachandran \cite{pettie:optimal}
24 which is provably optimal.
25
26 At the very heart of all these algorithms lies the \df{soft heap} discovered by
27 Chazelle \cite{chazelle:softheap}. It is a~meldable priority queue, roughly
28 similar to the Vuillemin's binomial heaps \cite{vuillemin:binheap} or Fredman's
29 and Tarjan's Fibonacci heaps \cite{ft:fibonacci}. The soft heaps run faster at
30 the expense of \df{corrupting} a~fraction of the inserted elements by raising
31 their values (the values are however never lowered). This allows for
32 a~trade-off between accuracy and speed, controlled by a~parameter~$\varepsilon$.
33 The heap operations take $\O(\log(1/\varepsilon))$ amortized time and at every
34 moment at most~$\varepsilon n$ elements of the~$n$ elements inserted can be
35 corrupted.
36
37 \defnn{Soft heap interface}%
38 The \df{soft heap} contains a~set of distinct items from a~totally ordered universe and it
39 supports the following operations:
40 \itemize\ibull
41 \:$\<Create>(\varepsilon)$ --- Create an~empty soft heap with the given accuracy parameter~$\varepsilon$.
42 \:$\<Insert>(H,x)$ --- Insert a~new item~$x$ into the heap~$H$.
43 \:$\<Meld>(P,Q)$ --- Merge two heaps into one, more precisely move all items of a~heap~$Q$
44   to the heap~$P$, destroying~$Q$ in the process. Both heaps must have the same~$\varepsilon$.
45 \:$\<DeleteMin>(H)$ --- Delete the minimum item of the heap~$H$ and return its value
46   (optionally signalling that the value has been corrupted).
47 \:$\<Explode>(H)$ --- Destroy the heap and return a~list of all items contained in it
48   (again optionally marking those corrupted).
49 \endlist
50
51 \>For every item, we will distinguish between its \df{original} value at the time
52 of insertion and its \df{current} value in the heap, which is possibly corrupted.
53
54 \examplen{Linear-time selection}
55 We can use soft heaps to select the median (or generally the $k$-th smallest element)
56 of a~sequence. We insert all $n$~elements to a~soft heap with error rate $\varepsilon=1/3$.
57 Then we delete the minimum about $n/3$ times and we remember the current value~$x$
58 of the last element deleted. This~$x$ is greater or equal than the current
59 values of the previously deleted elements and thus also than their original values.
60 On the other hand, the current values of the $2n/3$ elements remaining in the heap
61 are greater than~$x$ and at most $n/3$ of them are corrupted. Therefore at least $n/3$
62 original elements are greater than~$x$ and at least $n/3$ ones are smaller.
63
64 This allows us to use the~$x$ as a~pivot in the traditional divide-and-conquer algorithm
65 for selection (cf.~Hoare's Quickselect algorithm \cite{hoare:qselect}): We split the
66 input elements to three parts: $A$~contains those less than~$x$, $B$~those equal to~$x$
67 and $C$~those greater than~$x$. If $k\le\vert A\vert$, the desired element lies in~$A$,
68 so we can continue by finding the $k$-th smallest element of~$A$. If $\vert A\vert < k \le \vert
69 A\vert + \vert B\vert$, the desired element is $x$~itself. Otherwise, we search for the
70 $(k-\vert A\vert-\vert B\vert)$-th smallest element of~$C$. Either way, we have removed
71 at least $n/3$ items, so the total time complexity is
72 $\O(n+(2/3)\cdot n+(2/3)^2\cdot n+\ldots) = \O(n)$.
73
74 We have obtained a~nice alternative to the standard
75 linear-time selection algorithm of Blum \cite{blum:selection}. The same trick can be used
76 to select a~good pivot in Quicksort \cite{hoare:qsort}, leading to time complexity $\O(n\log n)$
77 in the worst case.
78
79 \defnn{Soft queues}
80 The soft heap is built from \df{soft queues} (we will usually omit the adjective soft
81 in the rest of this section). Each queue has a~shape of a~binary tree.\foot{%
82 Actually, Chazelle defines the queues as binomial trees, but he transforms them in ways that are
83 somewhat counter-intuitive, albeit well-defined. We prefer describing the queues as binary
84 trees with a~special distribution of values. In fact, the original C~code in the Chazelle's
85 paper \cite{chazelle:softheap} uses this representation internally.}
86 Each vertex~$v$ of the tree remembers a~doubly-linked list of items. The
87 item list in every left son will be used only temporarily and it will be kept
88 empty between operations. Only right sons and the root have their lists
89 permanently occupied. The left sons will be called \df{white}, the right ones
90 \df{black.} (See the picture.)
91
92 The first value in every list is called the \df{controlling key} of the vertex,
93 denoted by $\<ckey>(v)$. If the list is empty, we keep the most recently used
94 value or we set $\<ckey>(v)=+\infty$. The \<ckey>s obey the standard \df{heap order}
95 --- a~\<ckey> of a~parent is always smaller than the \<ckey>s of its sons.
96
97 Each vertex is also assigned its \df{rank,} which is a~non-negative integer.
98 The ranks of leaves are always zero, the rank of every internal vertex can be
99 arbitrary, but it must be strictly greater than the ranks of its sons. We
100 define the rank of the whole queue to be equal to the rank of its root vertex and
101 similarly for its \<ckey>.
102
103 A~queue is called \df{complete} if every two vertices joined by an~edge have rank
104 difference exactly one. In other words, it is a~complete binary tree and the
105 ranks correspond to vertex heights.
106
107 \figure{softheap1.eps}{\epsfxsize}{\multicap{A~complete and a~partial soft queue tree\\
108 (black vertices contain items, numbers indicate ranks)}}
109
110 \obs
111 The complete queue of rank~$k$ contains exactly~$2^{k+1}-1$ vertices, $2^k$~of which are
112 black (by induction). Any other queue can be trivially embedded to the complete queue of the same
113 rank, which we will call the \df{master tree} of the queue. This embedding preserves vertex
114 ranks, colors and the ancestor relation.
115
116 The queues have a~nice recursive structure. We can construct a~queue of rank~$k$ by \df{joining}
117 two queues of rank~$k-1$ under a~new root. The root will inherit the item list of one
118 of the original roots and also its \<ckey>. To preserve the heap order, we will choose
119 the son whose \<ckey> is smaller.
120
121 Sometimes, we will also need to split a~queue to smaller queues. We will call this operation
122 \df{dismantling} the queue and it will happen only in cases when the item list in the root
123 is empty. It suffices to remove the leftmost (all white) path going from the root. From
124 a~queue of rank~$k$, we get queues of ranks $0,1,\ldots,k-1$, some of which may be missing
125 if the original queue was not complete.
126
127 \figure{softheap2.eps}{\epsfxsize}{Joining and dismantling of soft queues}
128
129 We will now define the real soft heap and the operations on it.
130
131 \defn A~\df{soft heap} consists of:
132 \itemize\ibull
133 \:a~doubly linked list of soft queues of distinct ranks (in increasing order of ranks),
134   we will call the first queue the \df{head} of the list, the last queue will be its \df{tail};
135 \:\df{suffix minima:} each queue contains a~pointer to the queue with minimum \<ckey>
136 of those following it in the list;
137 \:a~global parameter~$r$: an~even integer to be set depending on~$\varepsilon$.
138 \endlist
139
140 \>We will define the \df{rank} of a~heap as the highest of the ranks of its queues
141 (that is, the rank of the heap's tail).
142
143 The heap always keeps the \df{Rank invariant:} When a~root of any tree has rank~$k$,
144 its leftmost path contains at least~$k/2$ vertices.
145
146 \paran{Operations on soft heaps}
147
148 \em{Melding} of two soft heaps involves merging of their lists of queues. We disassemble
149 the heap of the smaller rank and we insert its queues to the other heap.
150 If two queues of the same rank~$k$ appear in both lists, we \em{join} them to
151 a~single queue of rank~$k+1$ as already described and we propagate the new queue as
152 a~\df{carry} to the next iteration. (This is similar to addition of binary numbers.)
153 Finally, we have to update the suffix minima by walking the new list backwards
154 from the last inserted item.
155
156 \em{Creation} of a~new soft heap is trivial, \em{insertion} is handled by creating
157 a~single-element heap and melding it to the destination heap.
158
159 \algn{Creating a~new soft heap}
160 \algo
161 \algin The~parameter~$\varepsilon$ (the accuracy of the heap).
162 \:Allocate memory for a~new heap structure~$H$.
163 \:Initialize the list of queues in~$H$ to an~empty list.
164 \:Set the parameter~$r$ to~$2\lceil\log(1/\varepsilon)\rceil+2$ (to be justified later).
165 \algout A~newly minted soft heap~$H$.
166 \endalgo
167
168 \algn{Melding of two soft heaps}
169 \algo
170 \algin Two soft heaps~$P$ and~$Q$.
171 \:If $\<rank>(P) < \<rank>(Q)$, exchange the queue lists of~$P$ and~$Q$.
172 \:$p\=\<head>(P)$.
173 \brk\cmt{Whenever we run into an~end of a~list in this procedure, we assume that
174 there is an~empty queue of infinite rank there.}
175 \:While $Q$ still has some queues:
176 \::$q\=\<head>(Q)$.
177 \::If $\<rank>(p) < \<rank>(q)$, then $p\=$ the successor of~$p$,
178 \::else if $\<rank>(p) > \<rank>(q)$, remove~$q$ from~$Q$ and insert it to~$P$ before~$p$,
179 \::otherwise (the ranks are equal, we need to propagate the carry):
180 \:::$\<carry>\=p$.
181 \:::Remove~$p$ from~$P$ and set $p\=$ the original successor of~$p$.
182 \:::While $\<rank>(q)=\<rank>(\<carry>)$:
183 \::::Remove~$q$ from~$Q$.
184 \::::$\<carry>\=\<join>(q, \<carry>)$.
185 \::::$q\=\<head>(Q)$.
186 \:::Insert~\<carry> before~$q$.
187 \:Update the suffix minima: Walk with~$p$ backwards to the head of~$P$:
188 \::$p'\=\<suffix\_min>$ of the successor of~$p$.
189 \::If $\<ckey>(p) < \<ckey>(p')$, set $\<suffix\_min>(p)\=p$.
190 \::Otherwise set $\<suffix\_min>(p)\=p'$.
191 \:Destroy the heap~$Q$.
192 \algout The merged heap~$P$.
193 \endalgo
194
195 \algn{Insertion of an~element to a~soft heap}
196 \algo
197 \algin A~heap~$H$ and a~new element~$x$.
198 \:Create a~new heap~$H'$ of the same parameters as~$H$. Let~$H'$ contain a~sole queue of rank~0,
199   whose only vertex has the element~$x$ in its item list.
200 \:$\<Meld>(H,H')$.
201 \algout An~updated heap~$H$.
202 \endalgo
203
204 \paran{Corruption}%
205 So far, the mechanics of the soft heaps were almost identical to the binomial heaps
206 and the reader could rightfully yawn. The things are going to get interesting
207 now as we approach the parts where corruption of items takes place.
208
209 If all item lists contain at most one item equal to the \<ckey> of the particular
210 vertex, no information is lost and the heap order guarantees that the minimum item
211 of every queue stays in its root. We can however allow longer lists and let the items
212 stored in a~single list travel together between the vertices of the tree, still
213 represented by a~common \<ckey>. This data-structural analogue of car pooling will
214 allow the items to travel at a~faster rate, but as only a~single item can be equal
215 to the \<ckey>, all other items will be inevitably corrupted.
216
217 We of course have to be careful about the size of the lists, because we must avoid corrupting
218 too many items. We will control the growth according to the vertex ranks. Vertices
219 with rank at most~$r$ will always contain just a~single item. Above this level,
220 the higher is the rank, the longer list will be allowed.
221
222 \para
223 \em{Deletion of minimum} will be based on this principle. The minimum is easy to locate
224 --- we follow the \<suffix\_min> of the head of the heap to the queue with the minimum
225 \<ckey>. There we look inside the item list of the root of the queue. We remove the \em{last}
226 item from the list (we do not want the \<ckey> to change) and we return it as the minimum.
227 (It is not necessarily the real minimum of all items, but always the minimum of their
228 current, possibly corrupted values.)
229
230 If the list becomes empty, we \em{refill} it with items from the lower levels of the
231 same queue. This process can be best described recursively: We ask the left son to refill itself
232 (remember that the left son is always white, so there are currently no items there). If the new
233 \<ckey> of the left son is smaller than of the right son, we immediately move the left
234 son's list to its parent. Otherwise, we exchange the sons and move the list from the
235 new left son to the parent. This way we obey the heap order and at the same time we keep
236 the white left son free of items.
237
238 Occasionally, we repeat this process once again and we concatenate the resulting lists
239 (we append the latter list to the former, using the smaller of the two \<ckey>s). This
240 makes the lists grow longer and we want to do that roughly on every other level of the
241 tree. The exact condition will be that either the rank of the current vertex is odd,
242 or the difference in ranks between this vertex and its right son is at least two.
243
244 If refilling of the left son fails because there are no more items in that subtree
245 (we report this by setting the \<ckey> to $+\infty$), the current vertex is no longer
246 needed --- the items would just pass through it unmodified. We therefore want to
247 remove it. Instead of deleting it directly, we rather make it point to its former
248 grandsons and we remove the (now orphaned) original son. This helps us to ensure
249 that both sons always keep the same rank, which will be useful for the analysis.
250
251 When the refilling is over, we update the suffix minima by walking from the current
252 queue to the head of the heap exactly as we did in the \<Meld> procedure.
253
254 Our only remaining worry is that the Rank invariant can be broken after the
255 refilling. When the leftmost path of the tree becomes too short, we just
256 \em{dismantle} the tree as already described and we meld the new trees back to
257 the heap. This is easier to handle when the item list at the root vertex is
258 empty. We will therefore move this check before the refilling of the root list.
259 It will turn out that we have enough time to always walk the leftmost path
260 completely, so no explicit counters are needed.
261
262 Let us translate these ideas to real (pseudo)code:
263
264 \algn{Deleting the minimum item from a~soft heap}
265 \algo
266 \algin A~soft heap~$H$.
267 \:Use \<suffix\_min> of the head queue of~$H$ to locate the queue~$q$ with the smallest \<ckey>.
268 \:Remove the final element~$x$ of the item list in the root of~$q$.
269 \:If the item list became empty:
270 \::Count the vertices on the leftmost path of~$q$.
271 \::If there are less than $\<rank>(q)$ of them:
272 \:::Remove~$q$ from the list of queues.
273 \:::Recalculate the suffix minima as in the \<Meld> procedure.
274 \:::Dismantle~$q$ and create a~heap~$H'$ holding the resulting trees.
275 \:::Meld them back: $\<Meld>(H,H')$.
276 \::Otherwise:
277 \:::Call \<Refill> on the root of~$q$.
278 \:::If $\<ckey>(q)=+\infty$ (no items left), remove the tree~$q$ from~$H$.
279 \:::Recalculate the suffix minima.
280 \algout The deleted minimum item~$x$ (possibly corrupted).
281 \endalgo
282
283 \algn{Refilling the item list of a~vertex}
284 \algo
285 \algin A~soft queue and its vertex~$v$ with an~empty item list.
286 \:Handle trivial cases: If~$v$ has no children or both have $\<ckey>=+\infty$,
287   set $\<ckey>(v)$ to~$+\infty$ and return.
288 \:Let \<left> and~\<right> denote the respective sons of~$v$.
289 \:Recurse: call $\<Refill>(\<left>)$.
290 \:If $\<ckey>(\<left>) > \<ckey>(\<right>)$, swap the sons.
291 \:Move the item list from \<left> to~$v$ (implying $\<ckey>(v)=\<ckey>(\<left>)$).
292 \:If $\<rank>(v) > r$ and either $\<rank>(v)$ is odd or $\<rank>(v) > \<rank>(\<right>)+1$, recurse once more:
293 \::Repeat steps 3--4.
294 \::Append the item list from \<left> to the item list at~$v$.
295 \:Clean up. If $\<ckey>(\<right>) = +\infty$:
296 \::If $\<ckey>(\<left>) = +\infty$, unlink and discard both sons.
297 \::Otherwise relink the sons of \<left> to~$v$ and discard \<left>.
298 \algout A~modified soft queue.
299 \endalgo
300
301 \para
302 \<Explode> is trivial once we know how to recognize the corrupted items. It simply examines
303 all queues in the heap, walks the trees and the item lists of all vertices. It records
304 all items seen, the corrupted ones are those that different from their \<ckey>.
305
306 \paran{Analysis of accuracy}%
307 The description of the operations is now complete, so let us analyse their behavior
308 and verify that we have delivered what we promised --- first the accuracy of
309 the structure, then the time complexity of operations. In the whole analysis,
310 we will denote the total number of elements inserted during the history of the
311 structure by~$n$. We will also frequently take advantage of knowing that the
312 threshold~$r$ is even.
313
314 We start by bounding the sizes of the item lists.
315
316 \lemma
317 For every vertex~$v$ of a~soft queue, the size $\ell(v)$ of its item list
318 satisfies:
319 $$\ell(v) \le \max(1, 2^{\lceil \<rank>(v)/2 \rceil - r/2}).$$
320
321 \proof
322 Initially, all item lists contain at most one item, so the inequality trivially
323 holds. Let us continue by induction. Melds can affect the inequality only in the favorable
324 direction (they occasionally move an~item list to a~vertex of a~higher rank)
325 and so do deletes (they only remove items from lists). The only potentially
326 dangerous place is the \<Refill> procedure.
327
328 Refilling sometimes just moves items upwards, which is safe, and sometimes it
329 joins two lists into one, which generally is not. When $\<rank>(v) \le r$,
330 no joining takes place and~$\ell(v)$ is still~1. Otherwise we join when either
331 $\<rank>(v)$ is odd or $\<rank>(w) < \<rank>(v)-1$ for any son~$w$ of~$v$ (remember
332 that both sons have the same rank). In both cases, $\lceil\<rank>(w)/2\rceil \le
333 \lceil\<rank>(v)/2\rceil - 1$. By the induction hypothesis, the size of each
334 of the two lists being joined is at most $2^{\max(1,\lceil\<rank>(v)/2\rceil - 1 - r/2)}$,
335 so the new list has at most $2^{\lceil\<rank>(v)/2\rceil - r/2}$ items. (The maximum
336 has disappeared since $\<rank>(v)>r$ and therefore the desired bound is at least~2.)
337 \qed
338
339 We will now sum the sizes of the lists over all vertices containing corrupted items.
340
341 \lemma\id{shcorrlemma}%
342 At any given time, the heap contains at most~$n/2^{r-2}$ corrupted items.
343
344 \proof
345 We first prove an~auxiliary claim: The master trees of all queues contain at most~$n$
346 black vertices. This follows by induction: If no deletions have taken place,
347 there are exactly~$n$ black vertices, because insertion adds one black vertex and
348 melding preserves their number. A~deletion affects the master trees only when
349 dismantling takes place and then it only removes a~black vertex.
350
351 An~obvious upper bound on the number of corrupted items is the total size of item
352 lists in all vertices of rank greater than~$r$. We already know from the previous
353 lemma that the list sizes are limited by a~function of the ranks. A~complete tree
354 is obviously the worst case, so we will prove that this lemma holds for the master
355 tree of every queue in the heap. The actual trees can be much sparser, but the
356 above claim guarantees that the total size of the master trees is bounded by the
357 number of insertions properly.
358
359 So let us consider a~complete tree of~rank~$k$. It has exactly $2^{k-i}$ vertices
360 of rank~$i$ and each such vertex contains a~list of at most~$2^{\lceil i/2\rceil - r/2}$
361 items by the previous lemma. Summing over all ranks greater than~$r$, we get that
362 the total number of corrupted items in this tree is at most:
363 $$
364 \sum_{i=r+1}^k 2^{k-i}\cdot 2^{\lceil i/2\rceil - r/2}
365 = 2^{k-r/2} \cdot \sum_{i=r+1}^k 2^{\lceil i/2\rceil - i}
366 \le 2^{k-r/2+1/2} \cdot \sum_{i=r+1}^k 2^{-i/2}
367 \le 2^{k-r} \cdot \sum_{i=0}^\infty 2^{-i/2}.
368 $$
369 The sum of a~geometric series with quotient $2^{-1/2}$ is less than four, so the
370 last expression is less than $2^{k-r+2}$. Since the tree contains $n_k=2^k$ black vertices,
371 this makes less than $n_k/2^{r-2}$ corrupted items as we asserted.
372 \qed
373
374 \paran{Analysis of time complexity}%
375 Now we will examine the amortized time complexity of the individual operations.
376 We will show that if we charge $\O(r)$ time against every element inserted, it is enough
377 to cover the cost of all other operations.
378
379 All heap operations use only pointer operations, so it will be easy to derive the time
380 bound in the Pointer Machine model. The notable exception is however that the procedures
381 often refer to the ranks, which are integers on the order of $\log n$, so they cannot
382 fit in a~single memory cell. For the time being, we will assume that the ranks can
383 be manipulated in constant time, postponing the proof for later.
384
385 We take a~look at the melds first.
386
387 \lemma\id{shmeld}%
388 The amortized cost of a~meld is $\O(1)$, except for melds induced by dismantling
389 which take $\O(\<rank>(q))$, where $q$~is the queue to be dismantled.
390
391 \proof
392 The real cost of a~meld of heaps $P$ and~$Q$ is linear in the smaller of
393 their ranks, plus the time spent on carry propagation. The latter is easy to
394 dispose of: Every time there is a~carry, the total number of trees in all
395 heaps decreases by one. So it suffices to charge $\O(1)$ against creation of
396 a~tree. An~insert creates one tree, dismantling creates at most $\<rank>(q)$
397 trees, and all other operations alter only the internal structure of trees.
398
399 As for the $\O(\min(\<rank>(P),\<rank>(Q)))$ part, let us assume for a~while that
400 no dismantling ever takes place and consider the \df{meld forest.} It is a~forest
401 whose leaves correspond to the $n$~single-element heaps constructed by \<Insert>
402 and each internal vertex represents a~heap arisen from melding its sons. The left
403 son will be the one with the greater or equal rank. We therefore want to bound
404 the sum of ranks of all right sons.
405
406 For every right son, we will distribute the charge for its rank~$k$ among all leaves
407 in its subtree. There are at least $2^k$ such leaves. No leaf ever receives the same
408 rank twice, because the ranks of right sons on every path from the root of the
409 tree to a~leaf are strictly decreasing. (This holds because melding of two heaps
410 always produces a~heap of a~rank strictly greater than the smaller of the input ranks.) Hence at most~$n/2^k$
411 right sons have rank~$k$ and the total time charged against the leaves is bounded by:
412 $$
413 \sum_{k=0}^{\rm max. rank}k\cdot {n\over 2^k} \le n\cdot\sum_{k=0}^\infty {k\over 2^k} = 2n.
414 $$
415
416 Let us return dismantling to the game. When a~queue is dismantled, melding the parts
417 back to the heap takes $\O(\<rank>(q))$ time. We can therefore let the dismantling pay for it
418 and omit such induced melds from the meld forest. As the rank of a~heap is never increased
419 by induced melds, the above calculation is still a~proper upper bound on the cost
420 of the regular melds.
421 \qed
422
423 Before we estimate the time spent on deletions, we analyse the refills.
424
425 \lemma
426 Every invocation of the \<Refill> procedure takes time $\O(1)$ amortized.
427
428 \proof
429 When \<Refill> is called from the \<DeleteMin> operation, it recurses on a~subtree of the
430 queue. This subtree can be split to the ``lossless'' lower part (rank~$r$ and below)
431 and the upper part where list concatenation and thus also corruption takes place. Whenever
432 we visit the lower part during the recursion, we spend at worst $\O(r)$ time there.
433 We will prove that the total time spent in the upper parts during the whole life of the
434 data structure is $\O(n)$. Since each upper vertex can perform at most two calls to the lower
435 part, the total time spent in the lower parts is $\O(rn)$. All this can be prepaid by the
436 inserts.
437
438 Let us focus on the upper part. There are three possibilities of what can happen
439 when we visit a~vertex:
440
441 \itemize\ibull
442
443 \:We delete it: Every vertex deleted has to have been created at some time in the past.
444 New vertices are created only during inserts and melds (when joining two trees) and
445 we have already shown that these operations have constant amortized complexity. Then the
446 same must hold for deletions.
447
448 \:We recurse twice and concatenate the lists: The lists are disassembled only when
449 they reach the root of the tree, otherwise they are only concatenated. We can easily
450 model the situation by a~binary tree forest similar to the meld forest. There are~$n$
451 leaves and every internal vertex has outdegree two, so the total number of concatenations
452 is at most~$n$. Each of them can be performed in constant time as the list is doubly linked.
453
454 \:We recurse only once: This occurs only if the rank is even and the gap between the
455 rank of this vertex and its sons is equal to~1. It therefore cannot happen twice in a~row,
456 thus it is clearly dominated by the cost of the other possibilities.
457
458 \endlist
459 \>The total cost of all steps in the upper part is therefore $\O(n)$.
460 \qed
461
462 We now proceed with examining the \<DeleteMin> operation.
463
464 \lemma\id{shdelmin}%
465 Every \<DeleteMin> takes $\O(1)$ time amortized.
466
467 \proof
468 Aside from refilling, which is $\O(1)$ by the previous lemma, the \<DeleteMin>
469 takes care of the Rank invariant. This happens by checking the length of the leftmost
470 path and dismantling the tree if the length is too far from the tree's rank~$k$.
471 When the invariant is satisfied, the leftmost path is visited by the subsequent
472 call to \<Refill>, so we can account the check on the refilling.
473
474 When we are dismantling, we have to pay $\O(k)$ for the operation itself and
475 another $\O(k)$ for melding the trees back to the heap. Since we have produced at most
476 $k/2$ subtrees of distinct ranks, some subtree of rank $k/2$ or more must be missing.
477 Its master tree contained at least $2^{k/2}$ vertices which are now permanently gone
478 from the data structure, so we can charge the cost against them.
479 A~single vertex can participate in the master trees of several dismantlings, but their
480 ranks are always strictly increasing. By the same argument as in the proof of
481 Lemma \ref{shmeld} (complexity of \<Meld>), each vertex pays $\O(1)$.
482
483 We must not forget that \<DeleteMin> also has to recalculate the suffix minima.
484 In the worst case, it requires touching $k$~trees. Because of the Rank invariant,
485 this is linear in the size of the
486 leftmost path and therefore it can be also paid for by \<Refill>. (Incidentally,
487 this was the only place where we needed the invariant.)
488 \qed
489
490 \<Explode>s are easy not only to implement, but also to analyse:
491
492 \lemma
493 Every \<Explode> takes $\O(1)$ time amortized.
494
495 \proof
496 As all queues, vertices and items examined by \<Explode> are forever gone from the heap,
497 we can charge the constant time spent on each of them against the operations
498 that have created them.
499 \qed
500
501 It remains to take care of the calculation with ranks:
502
503 \lemma\id{shyards}%
504 Every manipulation with ranks performed by the soft heap operations can be
505 implemented on the Pointer Machine in constant amortized time.
506
507 \proof
508 We will recycle the idea of ``yardsticks'' from Section \ref{bucketsort}.
509 We create a~yardstick --- a~doubly linked list whose elements represent the possible
510 values of a~rank. Every vertex of a~queue will store its rank as a~pointer to
511 the corresponding ``tick'' of the yardstick. We will extend the list whenever necessary.
512
513 Comparison of two ranks for equality is then trivial, as is incrementing or decrementing
514 the rank by~1. Testing whether a~rank is odd can be handled by storing an~odd/even
515 flag in every tick. This covers all uses of ranks except for the comparisons for inequality
516 when melding. In step~1 of \<Meld>, we just mark the ticks of the two ranks and walk
517 the yardstick from the beginning until we come across a~mark. Thus we compare the ranks
518 in time proportional to the smaller of them, which is the real cost of the meld anyway.
519 The comparisons in steps 5 and~6 are trickier, but since the ranks of the elements put
520 to~$P$ are strictly increasing, we can start walking the list at the rank of the previous
521 element in~$P$. The cost is then the difference between the current and the previous rank
522 and the sum of these differences telescopes, again to the real cost of the meld.
523 \qed
524
525 Now we can put the bits together and laurel our effort with the following theorem:
526
527 \thmn{Performance of soft heaps, Chazelle \cite{chazelle:softheap}}\id{softheap}%
528 A~soft heap with error rate~$\varepsilon$ ($0<\varepsilon\le 1/2$) processes
529 a~sequence of operations starting with an~empty heap and containing $n$~\<Insert>s
530 in time $\O(n\log(1/\varepsilon))$ on the Pointer Machine. At every moment, the
531 heap contains at most $\varepsilon n$ corrupted items.
532
533 \proof
534 We set the parameter~$r$ to~$2+2\lceil\log (1/\varepsilon)\rceil$. The rest follows
535 from the analysis above. By Lemma \ref{shcorrlemma}, there are always at most $n/2^{r-2}
536 \le \varepsilon n$ corrupted items in the heap. By Lemma \ref{shmeld}--\ref{shyards},
537 the time spent on all operations in the sequence can be paid for by charging $\O(r)$ time
538 against each \<Insert>. This yields the time bound.
539 \qed
540
541 \rem
542 When we set $\varepsilon = 1/2n$, the soft heap is not allowed to corrupt any
543 items, so it can be used like any traditional heap. By the standard lower bound on
544 sorting it therefore requires $\Omega(\log n)$ time per operation, so the
545 time complexity is optimal for this choice of~$\varepsilon$. Chazelle \cite{chazelle:softheap}
546 proves that it is optimal for every choice of~$\varepsilon$.
547
548 The space consumed by the heap need not be linear in the \em{current} number
549 of items, but if a~case where this matters ever occurred, we could fix it easily
550 by rebuilding the whole data structure completely after $n/2$ deletes. This
551 increases the number of potentially corrupted items, but at worst twice, so it
552 suffices to decrease~$\varepsilon$ twice.
553
554 %--------------------------------------------------------------------------------
555
556 \section{Robust contractions}
557
558 Having the soft heaps at hand, we would like to use them in a~conventional MST
559 algorithm in place of a~normal heap. The most efficient specimen of a~heap-based
560 algorithm we have seen so far is the Iterated Jarn\'\i{}k's algorithm (\ref{itjar}).
561 It is based on a~simple, yet powerful idea: Run the Jarn\'\i{}k's algorithm with
562 limited heap size, so that it stops when the neighborhood of the tree becomes too
563 large. Grow multiple such trees, always starting in a~vertex not visited yet. All
564 these trees are contained in the MST, so by the Contraction lemma
565 (\ref{contlemma}) we can contract each of them to a~single vertex and iterate
566 the algorithm on the resulting graph.
567
568 We can try implanting the soft heap in this algorithm, preferably in the earlier
569 version without active edges (\ref{jarnik}) as the soft heap lacks the \<Decrease>
570 operation. This brave, but somewhat simple-minded attempt is however doomed to
571 fail. The reason is of course the corruption of items inside the heap, which
572 leads to increase of weights of some subset of edges. In presence of corrupted
573 edges, most of the theory we have so carefully built breaks down. For example,
574 the Blue lemma (\ref{bluelemma}) now holds only when we consider a~cut with no
575 corrupted edges, with a~possible exception of the lightest edge of the cut.
576 Similarly, the Red lemma (\ref{redlemma}) is true only if the heaviest edge on
577 the cycle is not corrupted.
578
579 There is fortunately some light in this darkness. While the basic structural
580 properties of MST's no longer hold, there is a~weaker form of the Contraction
581 lemma that takes the corrupted edges into account. Before we prove this lemma,
582 we expand our awareness of subgraphs which can be contracted.
583
584 \defn
585 A~subgraph $C\subseteq G$ is \df{contractible} iff for every pair of edges $e,f\in\delta(C)$\foot{That is,
586 of~$G$'s edges with exactly one endpoint in~$C$.} there exists a~path in~$C$ connecting the endpoints
587 of the edges $e,f$ such that all edges on this path are lighter than either $e$ or~$f$.
588
589 \example\id{jarniscont}%
590 Let us see that when we stop the Jarn\'\i{}k's algorithm at some moment and
591 we take a~subgraph~$C$ induced by the constructed tree, this subgraph is contractible.
592 Indeed, when we consider any two distinct edges $uv, xy$ having exactly one endpoint in~$C$
593 (w.l.o.g.~$u,x\in C$ and $v,y\not\in C$),
594 they enter the algorithm's heap at some time. Without loss of generality $uv$~enters it earlier.
595 Before the algorithm reaches the vertex~$x$, it adds the whole path $ux$ to the tree.
596 As the edge~$uv$ never leaves the heap, all edges on the path $ux$ must be lighter
597 than this edge.
598
599 We can now easily reformulate the Contraction lemma (\ref{contlemma}) in the language
600 of contractible subgraphs. We again assume that we are working with multigraphs
601 and that they need not be connected.
602 Furthermore, we slightly abuse the notation in the way that we omit the explicit bijection
603 between $G-C$ and~$G/C$, so we can write $G=C \cup (G/C)$.
604
605 \lemman{Generalized contraction}
606 When~$C\subseteq G$ is a~contractible subgraph, then $\msf(G)=\msf(C) \cup \msf(G/C)$.
607
608 \proof
609 As both sides of the equality are forests spanning the same graph, it suffices
610 to show that $\msf(G) \subseteq \msf(C)\cup\msf(G/C)$.
611 Let us show that edges of~$G$ that do not belong to the right-hand side
612 do not belong to the left-hand side either.
613 We know that the edges that
614 do not participate in the MSF of some graph are exactly those which are the heaviest
615 on some cycle (this is the Cycle rule from Lemma \ref{redlemma}).
616
617 Whenever an~edge~$g$ lies in~$C$, but not in~$\msf(C)$, then $g$~is the heaviest edge
618 on some cycle in~$C$. As this cycle is also contained in~$G$, the edge $g$~does not participate
619 in $\msf(G)$ either.
620
621 Similarly for $g\in (G/C)\setminus\msf(G/C)$: when the cycle does not contain
622 the vertex~$c$ to which we have contracted the subgraph~$C$, this cycle is present
623 in~$G$, too. Otherwise we consider the edges $e,f$ incident with~$c$ on this cycle.
624 Since $C$~is contractible, there must exist a~path~$P$ in~$C$ connecting the endpoints
625 of~$e$ and~$f$ in~$G$, such that all edges of~$P$ are lighter than either $e$ or~$f$
626 and hence also than~$g$. Expanding~$c$ in the cycle to the path~$P$ then produces
627 a~cycle in~$G$ whose heaviest edge is~$g$.
628 \qed
629
630 We are now ready to bring corruption back to the game and state a~``robust'' version
631 of this lemma. A~notation for corrupted graphs will be handy:
632
633 \nota\id{corrnota}%
634 When~$G$ is a~weighted graph and~$R$ a~subset of its edges, we will use $G\crpt
635 R$ to denote an arbitrary graph obtained from~$G$ by increasing the weights of
636 some of the edges in~$R$. As usually, we will assume that all edges of this graph
637 have pairwise distinct weights. While this is technically not true for the corruption
638 caused by soft heaps, we can easily make it so.
639
640 Whenever~$C$ is a~subgraph of~$G$, we will use $R^C$ to refer to the edges of~$R$ with
641 exactly one endpoint in~$C$ (i.e., $R^C = R\cap \delta(C)$).
642
643 \lemman{Robust contraction, Chazelle \cite{chazelle:almostacker}}\id{robcont}%
644 Let $G$ be a~weighted graph and $C$~its subgraph contractible in~$G\crpt R$
645 for some set~$R$ of edges. Then $\msf(G) \subseteq \msf(C) \cup \msf((G/C) \setminus R^C) \cup R^C$.
646
647 \proof
648 We will modify the proof of the previous lemma. We will again consider all possible types
649 of edges that do not belong to the right-hand side and we will show that they are the
650 heaviest edges of certain cycles. Every edge~$g$ of~$G$ lies either in~$C$, or in $H=(G/C)\setminus R^C$,
651 or possibly in~$R^C$.
652
653 If $g\in C\setminus\msf(C)$, then the same argument as before applies.
654
655 If $g\in H\setminus\msf(H)$, we consider the cycle in~$H$ on which $g$~is the heaviest.
656 When $c$ (the vertex to which we have contracted~$C$) is outside this cycle, we are done.
657 Otherwise we observe that the edges $e,f$ adjacent to~$c$ on this cycle cannot be corrupted
658 (they would be in~$R^C$ otherwise, which is impossible). By contractibility of~$C$ there exists
659 a~path~$P$ in~$C\crpt (R\cap C)$ such that all edges of~$P$ are lighter than $e$ or~$f$ and hence
660 also than~$g$. The weights of the edges of~$P$ in the original graph~$G$ cannot be higher than
661 in~$G\crpt R$, so the path~$P$ is lighter than~$g$ even in~$G$ and we can again perform the
662 trick with expanding the vertex~$c$ to~$P$ in the cycle~$C$. Hence $g\not\in\mst(G)$.
663 \qed
664
665 \para
666 We still intend to mimic the Iterative Jarn\'\i{}k's algorithm. We will partition the given graph to a~collection~$\C$
667 of non-overlapping contractible subgraphs called \df{clusters} and we put aside all edges that got corrupted in the process.
668 We recursively compute the MSF of those subgraphs and of the contracted graph. Then we take the
669 union of these MSF's and add the corrupted edges. According to the previous lemma, this does not produce
670 the MSF of~$G$, but a~sparser graph containing it, on which we can continue.
671
672 We can formulate the exact partitioning algorithm and its properties as follows:
673
674 \algn{Partition a~graph to a~collection of contractible clusters}\id{partition}%
675 \algo
676 \algin A~graph~$G$ with an~edge comparison oracle, a~parameter~$t$ controlling the size of the clusters,
677   and an~accuracy parameter~$\varepsilon$.
678 \:Mark all vertices as ``live''.
679 \:$\C\=\emptyset$, $R^\C\=\emptyset$. \cmt{Start with an~empty collection and no corrupted edges.}
680 \:While there is a~live vertex~$v_0$:
681 \::$T=\{v_0\}$. \cmt{the tree that we currently grow}
682 \::$K=\emptyset$. \cmt{edges known to be corrupted in the current iteration}
683 \::\<Create> a~soft heap with accuracy~$\varepsilon$ and \<Insert> the edges adjacent to~$v_0$ into it.
684 \::While the heap is not empty and $\vert T\vert \le t$:
685 \:::\<DeleteMin> an~edge $uv$ from the heap, assume $u\in T$.
686 \:::If $uv$ was corrupted, add it to~$K$.
687 \:::If $v\in T$, drop the edge and repeat the previous two steps.
688 \:::$T\=T\cup\{v\}$.
689 \:::If $v$ is dead, break out of the current loop.
690 \:::Insert all edges incident with~$v$ to the heap.
691 \::$\C\=\C \cup \{G[T]\}$. \cmt{Record the cluster induced by the tree.}
692 \::\<Explode> the heap and add all remaining corrupted edges to~$K$.
693 \::$R^\C\=R^\C \cup K^T$. \cmt{Record the ``interesting'' corrupted edges.}
694 \::$G\=G\setminus K^T$. \cmt{Remove the corrupted edges from~$G$.}
695 \::Mark all vertices of~$T$ as ``dead''.
696 \algout The collection $\C$ of contractible clusters and the set~$R^\C$ of
697 corrupted edges in the neighborhood of these clusters.
698 \endalgo
699
700 \thmn{Partitioning to contractible clusters, Chazelle \cite{chazelle:almostacker}}\id{partthm}%
701 Given a~weighted graph~$G$ and parameters $\varepsilon$ ($0<\varepsilon\le 1/2$)
702 and~$t$, the Partition algorithm (\ref{partition}) constructs a~collection
703 $\C=\{C_1,\ldots,C_k\}$ of clusters and a~set~$R^\C$ of edges such that:
704
705 \numlist\ndotted
706 \:All the clusters and the set~$R^\C$ are mutually edge-disjoint.
707 \:Each cluster contains at most~$t$ vertices.
708 \:Each vertex of~$G$ is contained in at least one cluster.
709 \:The connected components of the union of all clusters have at least~$t$ vertices each,
710   except perhaps for those which are equal to a~connected component of $G\setminus R^\C$.
711 \:$\vert R^\C\vert \le 2\varepsilon m$.
712 \:$\msf(G) \subseteq \bigcup_i \msf(C_i) \cup \msf\bigl((G / \bigcup_i C_i) \setminus R^\C\bigr) \cup R^\C$.
713 \:The algorithm runs in time $\O(n+m\log (1/\varepsilon))$.
714 \endlist
715
716 \proof
717 Claim~1: The Partition algorithm grows a~series of trees which induce the clusters~$C_i$ in~$G$.
718 A~tree is built from edges adjacent to live vertices
719 and once it is finished, all vertices of the tree die, so no edge is ever reused in another
720 tree. The edges that enter~$R^\C$ are immediately deleted from the graph, so they never participate
721 in any tree.
722
723 Claim~2: The algorithm stops when all vertices are dead, so each vertex must have
724 entered some tree.
725
726 Claim~3: The trees have at most~$t$ vertices each, which limits the size of the
727 $C_i$'s as well.
728
729 Claim~4: We can show that each connected component has $t$~or more vertices as we already did
730 in the proof of Lemma \ref{ijsize}: How can a~new tree stop growing? Either it acquires
731 $t$~vertices, or it joins one of the existing trees (this only increases the
732 size of the component), or the heap becomes empty (which means that the tree spans
733 a~full component of the current graph and hence also of the final~$G\setminus R^\C$).
734
735 Claim~5: The set~$R^\C$ contains a~subset of edges corrupted by the soft heaps over
736 the course of the algorithm. As every edge is inserted to a~heap at most once per
737 its endpoint, the heaps can corrupt at worst $2\varepsilon m$ edges altogether.
738
739 We will prove the remaining two claims as separate lemmata.
740 \qed
741
742 \lemman{Correctness of Partition, Claim 6 of Theorem \ref{partthm}}
743 $$\msf(G) \subseteq \bigcup_i \msf(C_i) \cup \msf\biggl( \bigl(G / \bigcup_i C_i \bigr) \setminus R^\C\biggr) \cup R^\C.$$
744
745 \proof
746 By iterating the Robust contraction lemma (\ref{robcont}). Let $K_i$ be the set of edges
747 corrupted when constructing the cluster~$C_i$ in the $i$-th phase of the algorithm,
748 and similarly for the state of the other variables at that time.
749 We will use induction on~$i$ to prove that the lemma holds at the end of every phase.
750
751 At the beginning, the statement is obviously true, even as an~equality.
752 In the $i$-th phase we construct the cluster~$C_i$ by running the partial Jarn\'\i{}k's algorithm on the graph
753 $G_i = G\setminus\bigcup_{j<i} K_{\smash j}^{C_j}$.
754 If it were not for corruption, the cluster~$C_i$ would be contractible, as we already know from Example \ref{jarniscont}.
755 When the edges in~$K_i$ get corrupted, the cluster is contractible in some corrupted graph
756 $G_i \crpt K_i$. (We have to be careful as the edges are becoming corrupted gradually,
757 but it is easy to check that it can only improve the situation.) Since $C_i$~shares no edges
758 with~$C_j$ for any~$j<i$, we know that~$C_i$ also a~contractible subgraph of $(G_i / \bigcup_{j<i} C_j) \crpt K_i$.
759 Now we can use the Robust contraction lemma to show that:
760 $$
761 \msf\biggl(\bigl(G / \bigcup_{j<i} C_j \bigr) \setminus \bigcup_{j<i} K_j^{C_j} \biggr) \subseteq
762 \msf(C_i) \cup \msf\biggl(\bigl(G / \bigcup_{j\le i} C_j \bigr) \setminus \bigcup_{j\le i} K_j^{C_j} \biggr) \cup K_i^{C_i}.
763 $$
764 This completes the induction step, because $K_j^{C_j} = K_j^{\C_j}$ for all~$j$.
765 \qed
766
767 \lemman{Efficiency of Partition, Claim 7 of Theorem \ref{partthm}}
768 The Partition algorithm runs in time $\O(n+m\log(1/\varepsilon))$.
769
770 \proof
771 The inner loop (steps 7--13) processes the edges of the current cluster~$C_i$ and also
772 the edges in its neighborhood $\delta(C_i)$. Steps 6 and~13 insert every such edge to the heap
773 at most once, so steps 8--12 visit each edge also at most once. For every edge, we spend
774 $\O(\log(1/\varepsilon))$ time amortized on inserting it and $\O(1)$ on the other operations
775 (by Theorem \ref{softheap} on performance of the soft heaps).
776
777 Each edge of~$G$ can participate in some $C_i\cup \delta(C_i)$ only twice before both its
778 endpoints die. The inner loop therefore processes $\O(m)$ edges total, so it takes $\O(m\log(1/\varepsilon))$
779 time. The remaining parts of the algorithm spend $\O(m)$ time on operations with clusters and corrupted edges
780 and additionally $\O(n)$ on identifying the live vertices.
781 \qed
782
783 %--------------------------------------------------------------------------------
784
785 \section{Decision trees}\id{dtsect}%
786
787 The Pettie's and Ramachandran's algorithm combines the idea of robust partitioning with optimal decision
788 trees constructed by brute force for very small subgraphs. In this section, we will
789 explain the basics of the decision trees and prove several lemmata which will
790 turn out to be useful for the analysis of time complexity of the final algorithm.
791
792 Let us consider all computations of some comparison-based MST algorithm when we
793 run it on a~fixed graph~$G$ with all possible permutations of edge weights.
794 The computations can be described by a~binary tree. The root of the tree corresponds to the first
795 comparison performed by the algorithm and depending to its result, the computation
796 continues either in the left subtree or in the right subtree. There it encounters
797 another comparison and so on, until it arrives to a~leaf of the tree where the
798 spanning tree found by the algorithm is recorded.
799
800 Formally, the decision trees are defined as follows:
801
802 \defnn{Decision trees and their complexity}\id{decdef}%
803 A~\df{MSF decision tree} for a~graph~$G$ is a~binary tree. Its internal vertices
804 are labeled with pairs of $G$'s edges to be compared, each of the two outgoing tree edges
805 corresponds to one possible result of the comparison.\foot{There are two possible
806 outcomes since there is no reason to compare an~edge with itself and we, as usually,
807 expect that the edge weights are distinct.}
808 Leaves of the tree are labeled with spanning trees of the graph~$G$.
809
810 A~\df{computation} of the decision tree on a~specific permutation of edge weights
811 in~$G$ is the path from the root to a~leaf such that the outcome of every comparison
812 agrees with the edge weights. The result of the computation is the spanning tree
813 assigned to its final leaf.
814 A~decision tree is \df{correct} iff for every permutation the corresponding
815 computation results in the real MSF of~$G$ with the particular weights.
816
817 The \df{time complexity} of a~decision tree is defined as its depth. It therefore
818 bounds the number of comparisons spent on every path. (It need not be equal since
819 some paths need not correspond to an~actual computation --- the sequence of outcomes
820 on the path could be unsatisfiable.)
821
822 A~decision tree is called \df{optimal} if it is correct and its depth is minimum possible
823 among the correct decision trees for the given graph.
824 We will denote an~arbitrary optimal decision tree for~$G$ by~${\cal D}(G)$ and its
825 complexity by~$D(G)$.
826
827 The \df{decision tree complexity} $D(m,n)$ of the MSF problem is the maximum of~$D(G)$
828 over all graphs~$G$ with $n$~vertices and~$m$ edges.
829
830 \obs
831 Decision trees are the most general deterministic comparison-based computation model possible.
832 The only operations that count in its time complexity are comparisons. All
833 other computation is free, including solving NP-complete problems or having
834 access to an~unlimited source of non-uniform constants. The decision tree
835 complexity is therefore an~obvious lower bound on the time complexity of the
836 problem in all other comparison-based models.
837
838 The downside is that we do not know any explicit construction of the optimal
839 decision trees, or at least a~non-constructive proof of their complexity.
840 On the other hand, the complexity of any existing comparison-based algorithm
841 can be used as an~upper bound on the decision tree complexity. For example:
842
843 \lemma
844 $D(m,n) \le 4/3 \cdot n^2$.
845
846 \proof
847 Let us count the comparisons performed by the Contractive Bor\o{u}vka's algorithm
848 (\ref{contbor}), tightening up the constants in its previous analysis in Theorem
849 \ref{contborthm}. In the first iteration, each edge participates in two comparisons
850 (one per endpoint), so the algorithm performs at most $2m \le 2{n\choose 2} \le n^2$
851 comparisons. Then the number of vertices drops at least by a~factor of two, so
852 the subsequent iterations spend at most $(n/2)^2, (n/4)^2, \ldots$ comparisons, which sums
853 to less than $n^2\cdot\sum_{i=0}^\infty (1/4)^i = 4/3 \cdot n^2$. Between the Bor\o{u}vka steps,
854 we flatten the multigraph to a~simple graph, which also needs some comparisons,
855 but for every such comparison we remove one of the participating edges, which saves
856 at least one comparison in the subsequent steps.
857 \qed
858
859 \para
860 Of course we can get sharper bounds from the better algorithms, but we will first
861 show how to find the optimal trees using brute force. The complexity of the search
862 will be of course enormous, but as we already promised, we will need the optimal
863 trees only for very small subgraphs.
864
865 \lemman{Construction of optimal decision trees}\id{odtconst}%
866 An~optimal MST decision tree for a~graph~$G$ on~$n$ vertices can be constructed on
867 the Pointer Machine in time $\O(2^{2^{4n^2}})$.
868
869 \proof
870 We will try all possible decision trees of depth at most $2n^2$
871 (we know from the previous lemma that the desired optimal tree is shallower). We can obtain
872 any such tree by taking the complete binary tree of exactly this depth
873 and labeling its $2\cdot 2^{2n^2}-1$ vertices with comparisons and spanning trees. Those labeled
874 with comparisons become internal vertices of the decision tree, the others
875 become leaves and the parts of the tree below them are removed. There are less
876 than $n^4$ possible comparisons and less than $2^{n^2}$ spanning trees of~$G$,
877 so the number of candidate decision trees is bounded by
878 $(n^4+2^{n^2})^{2^{2n^2+1}} \le 2^{(n^2+1)\cdot 2^{2n^2+1}} \le 2^{2^{2n^2+2}} \le 2^{2^{3n^2}}$.
879
880 We will enumerate the trees in an~arbitrary order, test each of them for correctness and
881 find the shallowest tree among those correct. Testing can be accomplished by running
882 through all possible permutations of edges, each time calculating the MSF using any
883 of the known algorithms and comparing it with the result given by the decision tree.
884 The number of permutations does not exceed $(n^2)! \le (n^2)^{n^2} \le n^{2n^2} \le 2^{n^3}$
885 and each permutation can be checked in time $\O(\poly(n))$.
886
887 On the Pointer Machine, trees and permutations can be certainly enumerated in time
888 $\O(\poly(n))$ per object. The time complexity of the whole algorithm is therefore
889 $\O(2^{2^{3n^2}} \cdot 2^{n^3} \cdot \poly(n)) = \O(2^{2^{4n^2}})$.
890 \qed
891
892 \paran{Basic properties of decision trees}%
893 The following properties will be useful for analysis of algorithms based
894 on precomputed decision trees. We will omit some technical details, referring
895 the reader to section 5.1 of the Pettie's article \cite{pettie:optimal}.
896
897 \lemma\id{dtbasic}%
898 The decision tree complexity $D(m,n)$ of the MSF satisfies:
899 \numlist\ndotted
900 \:$D(m,n) \ge m/2$ for $m,n > 2$.
901 \:$D(m',n') \ge D(m,n)$ whenever $m'\ge m$ and $n'\ge n$.
902 \endlist
903
904 \proof
905 For every $m,n>2$ there is a~graph on $n$~vertices and $m$~edges such that
906 every edge lies on a~cycle. Every correct MSF decision tree for this graph
907 has to compare each edge at least once. Otherwise the decision tree cannot
908 distinguish between the case when an~edge has the lowest of all weights (and
909 thus it is forced to belong to the MSF) and when it has the highest weight (so
910 it is forced out of the MSF).
911
912 Decision trees for graphs on $n'$~vertices can be used for graphs with $n$~vertices
913 as well --- it suffices to add isolated vertices, which does not change the MSF.
914 Similarly, we can increase $m$ to~$m'$ by adding edges parallel to an~existing
915 edge and making them heavier than the rest of the graph, so that they can never
916 belong to the MSF.
917 \qed
918
919 \defn
920 Subgraphs $C_1,\ldots,C_k$ of a~graph~$G$ are called the \df{compartments} of~$G$
921 iff they are edge-disjoint, their union is the whole graph~$G$ and
922 $\msf(G) = \bigcup_i \msf(C_i)$ for every permutation of edge weights.
923
924 \lemma\id{partiscomp}%
925 The clusters $C_1,\ldots,C_k$ generated by the Partition procedure of the
926 previous section (Algorithm \ref{partition}) are compartments of the graph
927 $H=\bigcup_i C_i$.
928
929 \proof
930 The first and second condition of the definition of compartments follow
931 from the Partitioning theorem (\ref{partthm}), so it remains to show that $\msf(H)$
932 is the union of the MSF's of the individual compartments. By the Cycle rule
933 (Lemma \ref{redlemma}), an~edge $h\in H$ is not contained in $\msf(H)$ if and only if
934 it is the heaviest edge on some cycle. It is therefore sufficient to prove that
935 every cycle in~$H$ is contained within a~single~$C_i$.
936
937 Let us consider a~cycle $K\subseteq H$ and a~cluster~$C_i$ such that it contains
938 an~edge~$e$ of~$K$ and all clusters constructed later by the procedure do not contain
939 any. If $K$~is not fully contained in~$C_i$, we can extend the edge~$e$ to a~maximal
940 path contained in both~$K$ and~$C_i$. Since $C_i$ shares at most one vertex with the
941 earlier clusters, there can be at most one edge from~$K$ adjacent to the maximal path,
942 which is impossible.
943 \qed
944
945 \lemma
946 Let $C_1,\ldots,C_k$ be compartments of a~graph~$G$. Then there exists an~optimal
947 MSF decision tree for~$G$ that does not compare edges of distinct compartments.
948
949 \proofsketch
950 Consider a~subset~$\cal P$ of edge weight permutations~$w$ that satisfy $w(e) < w(f)$
951 whenever $e\in C_i, f\in C_j, i<j$. For such permutations, no decision tree can
952 gain any information on relations between edge weights in a~single compartment by
953 inter-compartment comparisons --- the results of all such comparisons are determined
954 in advance.
955
956 Let us take an~arbitrary correct decision tree for~$G$ and restrict it to
957 vertices reachable by computations on~$\cal P$. Whenever a~vertex contained
958 an~inter-compartment comparison, it has lost one of its sons, so we can remove it
959 by contracting its only outgoing edge. We observe that we get a~decision tree
960 satisfying the desired condition and that this tree is correct.
961
962 As for the correctness, the MSF of a~single~$C_i$ is uniquely determined by
963 comparisons of its weights and the set~$\cal P$ contains all combinations
964 of orderings of weights inside individual compartments. Therefore every
965 spanning tree of every~$C_i$ and thus also of~$H$ is properly recognized.
966 \qed
967
968 \lemma\id{compartsum}%
969 Let $C_1,\ldots,C_k$ be compartments of a~graph~$G$. Then $D(G) = \sum_i D(C_i)$.
970
971 \proofsketch
972 A~collection of decision trees for the individual compartments can be ``glued together''
973 to a~decision tree for~$G$. We take the decision tree for~$C_1$, replace every its leaf
974 by a~copy of the tree for~$C_2$ and so on. Every leaf~$\ell$ of the compound tree will be
975 labeled with the union of labels of the original leaves encountered on the path from
976 the root to~$\ell$. This proves that $D(G) \le \sum_i D(C_i)$.
977
978 The other inequality requires more effort. We use the previous lemma to transform
979 the optimal decision tree for~$G$ to another of the same depth, but without inter-compartment
980 comparisons. Then we prove by induction on~$k$ and then on the depth of the tree
981 that this tree can be re-arranged, so that every computation first compares edges
982 from~$C_1$, then from~$C_2$ and so on. This means that the tree can be decomposed
983 to decision trees for the $C_i$'s. Also, without loss of efficiency all trees for
984 a~single~$C_i$ can be made isomorphic to~${\cal D}(C_i)$.
985 \qed
986
987 \cor\id{dtpart}%
988 If $C_1,\ldots,C_k$ are the clusters generated by the Partition procedure (Algorithm \ref{partition}),
989 then $D(\bigcup_i C_i) = \sum_i D(C_i)$.
990
991 \proof
992 Lemma \ref{partiscomp} tells us that $C_1,\ldots,C_k$ are compartments of the graph
993 $\bigcup C_i$, so we can apply Lemma \ref{compartsum} on them.
994 \qed
995
996 \cor\id{dttwice}%
997 $2D(m,n) \le D(2m,2n)$ for every $m,n$.
998
999 \proof
1000 For an~arbitrary graph~$G$ with $m$~edges and $n$~vertices, we create a~graph~$G_2$
1001 consisting of two copies of~$G$ sharing a~single vertex. The copies of~$G$ are obviously
1002 compartments of~$G_2$, so by Lemma \ref{compartsum} it holds that $D(G_2) = 2D(G)$.
1003 Taking a~maximum over all choices of~$G$ yields $D(2m,2n) \ge \max_G D(G_2) = 2D(m,n)$.
1004 \qed
1005
1006 %--------------------------------------------------------------------------------
1007
1008 \section{An optimal algorithm}\id{optalgsect}%
1009
1010 Once we have developed the soft heaps, partitioning and MST decision trees,
1011 it is now simple to state the Pettie's and Ramachandran's MST algorithm
1012 and prove that it is asymptotically optimal among all MST algorithms in
1013 comparison-based models. Several standard MST algorithms from the previous
1014 chapters will also play their roles.
1015
1016 We will describe the algorithm as a~recursive procedure. When the procedure is
1017 called on a~graph~$G$, it sets the parameter~$t$ to roughly $\log^{(3)} n$ and
1018 it calls the \<Partition> procedure to split the graph into a~collection of
1019 clusters of size~$t$ and a~set of corrupted edges. Then it uses precomputed decision
1020 trees to find the MSF of the clusters. The graph obtained by contracting
1021 the clusters is on the other hand dense enough, so that the Iterated Jarn\'\i{}k's
1022 algorithm runs on it in linear time. Afterwards we combine the MSF's of the clusters
1023 and of the contracted graphs, we mix in the corrupted edges and run two iterations
1024 of the Contractive Bor\o{u}vka's algorithm. This guarantees reduction in the number of
1025 both vertices and edges by a~constant factor, so we can efficiently recurse on the
1026 resulting graph.
1027
1028 \algn{Optimal MST algorithm, Pettie and Ramachandran \cite{pettie:optimal}}\id{optimal}%
1029 \algo
1030 \algin A~connected graph~$G$ with an~edge comparison oracle.
1031 \:If $G$ has no edges, return an~empty tree.
1032 \:$t\=\lfloor\log^{(3)} n\rfloor$. \cmt{the size of clusters}
1033 \:Call \<Partition> (\ref{partition}) on $G$ and $t$ with $\varepsilon=1/8$. It returns
1034   a~collection~$\C=\{C_1,\ldots,C_k\}$ of clusters and a~set~$R^\C$ of corrupted edges.
1035 \:$F_i \= \mst(C_i)$ for all~$i$, obtained using optimal decision trees.
1036 \:$G_A \= (G / \bigcup_i C_i) \setminus R^\C$. \cmt{the contracted graph}
1037 \:$F_A \= \msf(G_A)$ calculated by the Iterated Jarn\'\i{}k's algorithm (\ref{itjar}).
1038 \:$G_B \= \bigcup_i F_i \cup F_A \cup R^\C$. \cmt{combine subtrees with corrupted edges}
1039 \:Run two Bor\o{u}vka steps (iterations of the Contractive Bor\o{u}vka's algorithm, \ref{contbor}) on~$G_B$,
1040   getting a~contracted graph~$G_C$ and a~set~$F_B$ of MST edges.
1041 \:$F_C \= \mst(G_C)$ obtained by a~recursive call to this algorithm.
1042 \:Return $F_B \cup F_C$.
1043 \algout The minimum spanning tree of~$G$.
1044 \endalgo
1045
1046 Correctness of this algorithm immediately follows from the Partitioning theorem (\ref{partthm})
1047 and from the proofs of the respective algorithms used as subroutines. Let us take a~look at
1048 the time complexity. We will be careful to use only the operations offered by the Pointer Machine.
1049
1050 \lemma\id{optlemma}%
1051 The time complexity $T(m,n)$ of the Optimal algorithm satisfies the following recurrence:
1052 $$
1053 T(m,n) \le \sum_i c_1 D(C_i) + T(m/2, n/4) + c_2 m,
1054 $$
1055 where~$c_1$ and~$c_2$ are some positive constants and $D$~is the decision tree complexity
1056 from the previous section.
1057
1058 \proof
1059 The first two steps of the algorithm are trivial as we have linear time at our
1060 disposal.
1061
1062 By the Partitioning theorem (\ref{partthm}), the call to \<Partition> with~$\varepsilon$
1063 set to a~constant takes $\O(m)$ time and it produces a~collection of clusters of size
1064 at most~$t$ and at most $m/4$ corrupted edges. It also guarantees that the
1065 connected components of the union of the $C_i$'s have at least~$t$ vertices
1066 (unless there is just a~single component).
1067
1068 To apply the decision trees, we will use the framework of topological computations developed
1069 in Section \ref{bucketsort}. We pad all clusters in~$\C$ with isolated vertices, so that they
1070 have exactly~$t$ vertices. We use a~computation that labels the graph with a~pointer to
1071 its optimal decision tree. Then we apply Theorem \ref{topothm} combined with the
1072 brute-force construction of optimal decision trees from Lemma \ref{odtconst}. Together they guarantee
1073 that we can assign the decision trees to the clusters in time:
1074 $$\O\Bigl(\Vert\C\Vert + t^{t(t+2)} \cdot \bigl(2^{2^{4t^2}} + t^2\bigr)\Bigr)
1075 = \O\Bigl(m + 2^{2^{2^t}}\Bigr)
1076 = \O(m).$$
1077 Execution of the decision tree on each cluster~$C_i$ then takes $\O(D(C_i))$ steps.
1078
1079 The contracted graph~$G_A$ has at most $n/t = \O(n / \log^{(3)}n)$ vertices and asymptotically
1080 the same number of edges as~$G$, so according to Corollary \ref{ijdens}, the Iterated Jarn\'\i{}k's
1081 algorithm runs on it in linear time.
1082
1083 The combined graph~$G_B$ has~$n$ vertices, but less than~$n$ edges from the
1084 individual spanning trees and at most~$m/4$ additional edges which were
1085 corrupted. The Bor\o{u}vka steps on~$G_B$ take $\O(m)$
1086 time by Lemma \ref{boruvkaiter} and they produce a~graph~$G_C$ with at most~$n/4$
1087 vertices and at most $n/4 + m/4 \le m/2$ edges. (The $n$~tree edges in~$G_B$ are guaranteed
1088 to be reduced by the Bor\o{u}vka's algorithm.) It is easy to verify that this
1089 graph is still connected, so we can recurse on it.
1090
1091 The remaining steps of the algorithm can be easily performed in linear time either directly
1092 or in case of the contractions by the bucket-sorting techniques of Section \ref{bucketsort}.
1093 \qed
1094
1095 \paran{Optimality}%
1096 The properties of decision tree complexity, which we have proven in the previous
1097 section, will help us show that the time complexity recurrence is satisfied by a~constant
1098 multiple of the decision tree complexity $D(m,n)$ itself. This way, we will prove
1099 the following theorem:
1100
1101 \thmn{Optimality of the Optimal algorithm}
1102 The time complexity of the Optimal MST algorithm \ref{optimal} is $\Theta(D(m,n))$.
1103
1104 \proof
1105 We will prove by induction that $T(m,n) \le cD(m,n)$ for some $c>0$. The base
1106 case is trivial, for the induction step we will expand on the previous lemma:
1107 \def\eqalign#1{\null\,\vcenter{\openup\jot
1108   \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
1109       \crcr#1\crcr}}\,}
1110 $$\vcenter{\openup\jot\halign{\strut\hfil $\displaystyle{#}$&$\displaystyle{{}#}$\hfil&\quad#\hfil\cr
1111 T(m,n)
1112     &\le \sum_i c_1 D(C_i) + T(m/2, n/4) + c_2 m &(Lemma \ref{optlemma})\cr
1113     &\le c_1 D({\textstyle\bigcup}_i C_i) + T(m/2, n/4) + c_2 m &(Corollary \ref{dtpart})\cr
1114     &\le c_1 D(m,n) + T(m/2, n/4) + c_2m &(definition of $D(m,n)$)\cr
1115     &\le c_1 D(m,n) + cD(m/2, n/4) + c_2m &(induction hypothesis)\cr
1116     &\le c_1 D(m,n) + c/2\cdot D(m,n/2) + c_2m &(Corollary \ref{dttwice})\cr
1117     &\le c_1 D(m,n) + c/2\cdot D(m,n) + 2c_2 D(m,n) &(Lemma \ref{dtbasic})\cr
1118     &\le (c_1 + c/2 + 2c_2) \cdot D(m,n)&\cr
1119     &\le cD(m,n). &(by setting $c=2c_1+4c_2$)\cr
1120 }}$$
1121 The other inequality is obvious as $D(m,n)$ is an~asymptotic lower bound on
1122 the time complexity of every comparison-based algorithm.
1123 \qed
1124
1125 \paran{Complexity of MST}%
1126 As we have already noted, the exact decision tree complexity $D(m,n)$ of the MST problem
1127 is still open and so therefore is the time complexity of the optimal algorithm. However,
1128 every time we come up with another comparison-based algorithm, we can use its complexity
1129 (or more specifically the number of comparisons it performs, which can be even lower)
1130 as an~upper bound on the optimal algorithm.
1131
1132 The best explicit comparison-based algorithm known to date achieves complexity $\O(m\timesalpha(m,n))$.\foot{$\alpha(m,n)$
1133 is a~certain inverse of the Ackermann's function, $\lambda_k(n)$ is the row inverse of the same
1134 function. See \ref{ackerinv} for the exact definitions.}
1135 It has been discovered by Chazelle \cite{chazelle:ackermann} as an~improvement of his previous
1136 $\O(m\timesalpha(m,n)\cdot\log\alpha(m,n))$ algorithm \cite{chazelle:almostacker}.
1137 It is also based on the ideas of this chapter --- in particular the soft heaps and robust contractions.
1138 The algorithm is very complex and it involves a~lot of elaborate
1139 technical details, so we only refer to the original paper here. Another algorithm of the same
1140 complexity, using similar ideas, has been discovered independently by Pettie \cite{pettie:ackermann}, who,
1141 having the optimal algorithm at hand, does not take care about the low-level details and he only
1142 bounds the number of comparisons. Using any of these results, we can prove an~Ackermannian
1143 upper bound on the optimal algorithm:
1144
1145 \thmn{Upper bound on complexity of the Optimal algorithm}\id{optthm}%
1146 The time complexity of the Optimal MST algorithm is $\O(m\alpha(m,n))$.
1147
1148 \proof
1149 We bound $D(m,n)$ by the number of comparisons performed by the algorithm of Chazelle \cite{chazelle:ackermann}
1150 or Pettie \cite{pettie:ackermann}.
1151 \qed
1152
1153 Similarly to the Iterated Jarn\'\i{}k's algorithm, this bound is actually linear for classes of graphs
1154 that do not have density extremely close to constant:
1155
1156 \cor\id{lambdacor}%
1157 The Optimal MST algorithm runs in linear time whenever $m\ge n\cdot \lambda_k(n)$ for any fixed~$k$.
1158
1159 \proof
1160 Combine the previous theorem with Lemma \ref{alphaconst}.
1161 \qed
1162
1163 \rem
1164 It is also known from \cite{pettie:optimal} that when we run the Optimal algorithm on a~random
1165 graph drawn from either $G_{n,p}$ (random graphs on~$n$ vertices, each edge is included with probability~$p$
1166 independently on the other edges) or $G_{n,m}$ (we draw the graph uniformly at random from the
1167 set of all graphs with~$n$ vertices and $m$~edges), it runs in linear time with high probability,
1168 regardless of the edge weights.
1169
1170 \paran{Models of computation}%
1171 Another important consequence of the optimal algorithm is that when we aim for a~linear-time
1172 MST algorithm (or for proving that it does not exist), we do not need to care about computational
1173 models at all. The elaborate RAM data structures of Chapter \ref{ramchap}, which have helped us
1174 so much in the case of integer weights, cannot help if we are allowed to access the edge weights
1175 by performing comparisons only. We can even make use of non-uniform objects given by some sort
1176 of oracle. Indeed, whatever trick we employ to achieve linear time complexity, we can mimic it in the
1177 world of decision trees and thus we can use it to show that the algorithm we already knew is
1178 also linear.
1179
1180 This however applies to deterministic algorithms only --- we have shown that access to a~source
1181 of random bits allows us to compute the MST in expected linear time (the KKT algorithm, \ref{kkt}).
1182 There were attempts to derandomize the KKT algorithm, but so far the best result in this direction
1183 is the randomized algorithm also by Pettie \cite{pettie:minirand} which achieves expected linear time
1184 complexity with only $\O(\log^* n)$ random bits.
1185
1186 \endpart