X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=mst.tex;h=efc4d63238fe433e81007b922e78d9487b477198;hb=3ce379fec86d6348c80aa1d8c77fb64a0dbada13;hp=85c8b455f20f518abd729b83618b9a760f1ef9d5;hpb=7410c61b6118068ca55e3be90f0e92e8057d24a3;p=saga.git diff --git a/mst.tex b/mst.tex index 85c8b45..efc4d63 100644 --- a/mst.tex +++ b/mst.tex @@ -24,7 +24,7 @@ find its minimum spanning tree, defined as follows: For a given graph~$G$ with weights $w:E(G)\rightarrow {\bb R}$: \itemize\ibull \:A~subgraph $H\subseteq G$ is called a \df{spanning subgraph} if $V(H)=V(G)$. -\:A~\df{spanning tree} of $G$ is any its spanning subgraph that is a tree. +\:A~\df{spanning tree} of~$G$ is any spanning subgraph of~$G$ that is a tree. \:For any subgraph $H\subseteq G$ we define its \df{weight} $w(H):=\sum_{e\in E(H)} w(e)$. When comparing two weights, we will use the terms \df{lighter} and \df{heavier} in the obvious sense. @@ -41,23 +41,25 @@ spanning tree problem was one of the central topics of the flourishing new disciplines, the previous work was not well known and the algorithms had to be rediscovered several times. -Recently, several significantly faster algorithms were discovered, most notably the -$\O(m\timesbeta(m,n))$-time algorithm by Fredman and Tarjan \cite{ft:fibonacci} and -algorithms with inverse-Ackermann type complexity by Chazelle \cite{chazelle:ackermann} -and Pettie \cite{pettie:ackermann}. +In the next 50 years, several significantly faster algorithms were discovered, ranging +from the $\O(m\timesbeta(m,n))$ time algorithm by Fredman and Tarjan \cite{ft:fibonacci}, +over algorithms with inverse-Ackermann type complexity by Chazelle \cite{chazelle:ackermann} +and Pettie \cite{pettie:ackermann}, to another algorithm by Pettie \cite{pettie:optimal} +whose time complexity is provably optimal. -\FIXME{Write the rest of the history.} - -This chapter attempts to survey the important algorithms for finding the MST and it -also presents several new ones. +In the upcoming chapters, we will explore this colorful universe of MST algorithms. +We will meet the canonical works of the classics, the clever ideas of their successors, +various approaches to the problem including randomization and solving of important +special cases. At several places, we will try to contribute our little stones to this +mosaic. %-------------------------------------------------------------------------------- -\section{Basic properties} +\section{Basic properties}\id{mstbasics}% In this section, we will examine the basic properties of spanning trees and prove -several important theorems to base the algorithms upon. We will follow the theory -developed by Tarjan in~\cite{tarjan:dsna}. +several important theorems which will serve as a~foundation for our MST algorithms. +We will mostly follow the theory developed by Tarjan in~\cite{tarjan:dsna}. For the whole section, we will fix a~connected graph~$G$ with edge weights~$w$ and all other graphs will be spanning subgraphs of~$G$. We will use the same notation @@ -79,9 +81,9 @@ Let~$T$ be a~spanning tree. Then: \endlist \rem -Edges of the tree~$T$ itself are neither heavy nor light. We will sometimes -use the name \df{non-heavy} for edges which are either light or contained -in the tree. +Edges of the tree~$T$ cover only themselves and thus they are neither heavy nor light. +The same can happen if an~edge outside~$T$ covers only edges of the same weight, +but this will be rare because all edge weights will be usually distinct. \lemman{Light edges}\id{lightlemma}% Let $T$ be a spanning tree. If there exists a $T$-light edge, then~$T$ @@ -125,7 +127,7 @@ hypothesis to $T^*$ and $T'$ to get the rest of the exchange sequence. \lemman{Monotone exchanges}\id{monoxchg}% Let $T$ be a spanning tree such that there are no $T$-light edges and $T'$ be an arbitrary spanning tree. Then there exists a sequence of edge exchanges -transforming $T$ to~$T'$ such that the weight does not increase in any step. +transforming $T$ to~$T'$ such that the weight does not decrease in any step. \proof We improve the argument from the previous proof, refining the induction step. @@ -147,7 +149,7 @@ $w(f)\ge w(e')$ due to the choice of $e'$ and all other edges on~$C$ are lighter than~$e'$ as $e'$ was not $T$-light. \qed -\thmn{Minimality by order}\id{mstthm}% +\thmn{Minimality of spanning trees}\id{mstthm}% A~spanning tree~$T$ is minimum iff there is no $T$-light edge. \proof @@ -166,7 +168,7 @@ minimum spanning trees according to the Cayley's formula \cite{cayley:trees}). However, as the following theorem shows, this is possible only if the weight function is not injective. -\thmn{MST uniqueness}% +\thmn{Uniqueness of MST}% If all edge weights are distinct, then the minimum spanning tree is unique. \proof @@ -179,41 +181,58 @@ we know that $w(T_1)=w(T_2)$, so the exchange sequence must be empty and indeed $T_1$ and $T_2$ must be identical. \qed -\rem\id{edgeoracle}% -To simplify the description of MST algorithms, we will expect that the weights -of all edges are distinct and that instead of numeric weights (usually accompanied -by problems with representation of real numbers in algorithms) we will be given -a comparison oracle, that is a function which answers questions ``$w(e) +and \. The \ operation tests whether two elements are equivalent and \ +joins two different equivalence classes into one. + +\para +We can maintain the connected components of our forest~$T$ as equivalence classes. When we want +to add an~edge~$uv$, we first call $\(u,v)$ to check if both endpoints of the edge lie in +the same components. If they do not, addition of this edge connects both components into one, +so we perform $\(u,v)$ to merge the equivalence classes. + +Tarjan and van Leeuwen have shown that there is a~data structure for the DSU problem +with surprising efficiency: + +\thmn{Disjoint Set Union, Tarjan and van Leeuwen \cite{tarjan:setunion}}\id{dfu}% +Starting with a~trivial equivalence with single-element classes, a~sequence of operations +comprising of $n$~\s intermixed with $m\ge n$~\s can be processed in time +$\O(m\timesalpha(m,n))$, where $\alpha(m,n)$ is a~certain inverse of the Ackermann's function +(see Definition \ref{ackerinv}). \proof -Proven by Tarjan and van Leeuwen in \cite{tarjan:setunion}. +See \cite{tarjan:setunion}. \qed -\FIXME{Define Ackermann's function. Use $\alpha(m,n)$?} +This completes the following theorem: + +\thm\id{kruskal}% +Kruskal's algorithm finds the MST of a given graph in time $\O(m\log n)$. +If the edges are already sorted by their weights, the time drops to +$\O(m\timesalpha(m,n))$. + +\proof +We spend $\O(m\log n)$ on sorting, $\O(m\timesalpha(m,n))$ on processing the sequence +of \s and \s, and $\O(m)$ on all other work. +\qed \rem -The cost of the operations on components is of course dwarfed by the complexity +The cost of the \ and \ operations is of course dwarfed by the complexity of sorting, so a much simpler (at least in terms of its analysis) data structure would be sufficient, as long as it has $\O(\log n)$ amortized complexity per operation. For example, we can label vertices with identifiers of the -corresponding components and always recolor the smaller of the two components. - -\thm\id{kruskal}% -Kruskal's algorithm finds the MST of a given graph in time $\O(m\log n)$ -or $\O(m\timesalpha(n))$ if the edges are already sorted by their weights. +corresponding components and always relabel the smaller of the two components. -\proof -Follows from the above analysis. -\qed +We will study dynamic maintenance of connected components in more detail in Chapter~\ref{dynchap}. %-------------------------------------------------------------------------------- @@ -478,7 +556,7 @@ Follows from the above analysis. While the classical algorithms are based on growing suitable trees, they can be also reformulated in terms of edge contraction. Instead of keeping -a forest of trees, we can keep each tree contracted to a single vertex. +a~forest of trees, we can keep each tree contracted to a single vertex. This replaces the relatively complex tree-edge incidencies by simple vertex-edge incidencies, potentially speeding up the calculation at the expense of having to perform the contractions. @@ -505,14 +583,10 @@ Then $G'$~has the same MST as~$G$. \proof Every spanning tree of~$G'$ is a spanning tree of~$G$. In the other direction: Loops can be never contained in a spanning tree. If there is a spanning tree~$T$ -containing a~removed edge~$e$ parallel to an edge~$e'\in G'$, exchaning $e'$ -for~$e$ makes~$T$ lighter. \qed - -\rem Removal of the heavier of a pair of parallel edges can be also viewed -as an application of the Red rule on a two-edge cycle. And indeed it is, the -Red-Blue procedure works on multigraphs as well as on simple graphs and all the -classical algorithms also do. We would only have to be more careful in the -formulations and proofs, which we preferred to avoid. +containing a~removed edge~$e$ parallel to an edge~$e'\in G'$, exchanging $e'$ +for~$e$ makes~$T$ lighter. (This is indeed the multigraph version of the Red +lemma applied to a~two-edge cycle, as we will see in \ref{multimst}.) +\qed \algn{Contractive version of Bor\o{u}vka's algorithm}\id{contbor} \algo @@ -522,7 +596,7 @@ formulations and proofs, which we preferred to avoid. \:While $n(G)>1$: \::For each vertex $v_k$ of~$G$, let $e_k$ be the lightest edge incident to~$v_k$. \::$T\=T\cup \{ \ell(e_k) \}$. \cmt{Remember labels of all selected edges.} -\::Contract $G$ along all edges $e_k$, inheriting labels and weights.\foot{In other words, we ask the comparison oracle for the edge $\ell(e)$ instead of~$e$.} +\::Contract all edges $e_k$, inheriting labels and weights.\foot{In other words, we ask the comparison oracle for the edge $\ell(e)$ instead of~$e$.} \::Flatten $G$, removing parallel edges and loops. \algout Minimum spanning tree~$T$. \endalgo @@ -533,13 +607,13 @@ at the beginning of the $i$-th iteration by $G_i$ (starting with $G_0=G$) and th of vertices and edges of this graph by $n_i$ and $m_i$ respectively. \lemma\id{contiter}% -The $i$-th iteration of the algorithm (also called the Bor\o{u}vka step) can be carried +The $i$-th iteration of the algorithm (also called the \df{Bor\o{u}vka step}) can be carried out in time~$\O(m_i)$. \proof The only non-trivial parts are steps 6 and~7. Contractions can be handled similarly to the unions in the original Bor\o{u}vka's algorithm (see \ref{boruvkaiter}): -We build an auxillary graph containing only the selected edges~$e_k$, find +We build an auxiliary graph containing only the selected edges~$e_k$, find connected components of this graph and renumber vertices in each component to the identifier of the component. This takes $\O(m_i)$ time. @@ -549,7 +623,7 @@ edges together. The bucket sort uses two passes with $n_i$~buckets, so it takes $\O(n_i+m_i)=\O(m_i)$. \qed -\thm +\thm\id{contborthm}% The Contractive Bor\o{u}vka's algorithm finds the MST of the input graph in time $\O(\min(n^2,m\log n))$. @@ -590,13 +664,13 @@ in section~\ref{minorclosed}. To achieve the linear time complexity, the algorithm needs a very careful implementation, but we defer the technical details to section~\ref{bucketsort}. -\para +\paran{General contractions}% Graph contractions are indeed a~very powerful tool and they can be used in other MST algorithms as well. The following lemma shows the gist: \lemman{Contraction of MST edges}\id{contlemma}% Let $G$ be a weighted graph, $e$~an arbitrary edge of~$\mst(G)$, $G/e$ the multigraph -produced by contracting $G$ along~$e$, and $\pi$ the bijection between edges of~$G-e$ and +produced by contracting~$e$ in~$G$, and $\pi$ the bijection between edges of~$G-e$ and their counterparts in~$G/e$. Then: $$\mst(G) = \pi^{-1}[\mst(G/e)] + e.$$ \proof @@ -617,11 +691,11 @@ which obviously works in multigraphs as well.) \rem In the previous algorithm, the role of the mapping~$\pi^{-1}$ is of course played by the edge labels~$\ell$. -\para -Finally, we will show a family of graphs where the $\O(m\log n)$ bound on time complexity +\paran{A~lower bound}% +Finally, we will show a family of graphs for which the $\O(m\log n)$ bound on time complexity is tight. The graphs do not have unique weights, but they are constructed in a way that the algorithm never compares two edges with the same weight. Therefore, when two such -graphs are monotonely isomorphic (see~\ref{mstiso}), the algorithm processes them in the same way. +graphs are monotonically isomorphic (see~\ref{mstiso}), the algorithm processes them in the same way. \defn A~\df{distractor of order~$k$,} denoted by~$D_k$, is a path on $n=2^k$~vertices $v_1,\ldots,v_n$ @@ -675,7 +749,16 @@ to finish on the remaining complete graph. Each iteration runs on a graph with $ edges as every $H_{a,k}$ contains a complete graph on~$a$ vertices. \qed -\remn{Disconnected graphs}\id{disconn}% +%-------------------------------------------------------------------------------- + +\section{Lifting restrictions} + +In order to have a~simple and neat theory, we have introduced several restrictions +on the graphs in which we search for the MST. As in some rare cases we are going to +meet graphs that do not fit into this simplified world, let us quickly examine what +happens when the restrictions are lifted. + +\paran{Disconnected graphs}\id{disconn}% The basic properties of minimum spanning trees and the algorithms presented in this chapter apply to minimum spanning forests of disconnected graphs, too. The proofs of our theorems and the steps of our algorithms are based on adjacency @@ -690,4 +773,31 @@ for $F$-light). Edges connecting two different trees are always considered $F$-light. Again, a~spanning forest~$F$ is minimum iff there are no $F$-light edges. +\paran{Multigraphs}\id{multimst}% +All theorems and algorithms from this chapter work for multigraphs as well, +only the notation sometimes gets crabbed, which we preferred to avoid. The Minimality +theorem and the Blue rule stay unchanged. The Red rule is naturally extended to +self-loops (which are never in the MST) and two-edge cycles (where the heavier +edge can be dropped) as already suggested in the Flattening lemma (\ref{flattening}). + +\paran{Multiple edges of the same weight}\id{multiweight}% +In case when the edge weights are not distinct, the characterization of minimum +spanning trees using light edges is still correct, but the MST is no longer unique +(as already mentioned, there can be as much as~$n^{n-2}$ MST's). + +In the Red-Blue procedure, we have to avoid being too zealous. The Blue lemma cannot +guarantee that when a~cut contains multiple edges of the minimum weight, all of them +are in the MST. It will however tell that if we pick one of these edges, an~arbitrary +MST can be modified to another MST that contains this edge. Therefore the Blue rule +will change to ``Pick a~cut~$C$ such that it does not contain any blue edge and color +one of its lightest edges blue.'' The Red lemma and the Red rule can be handled +in a~similar manner. The modified algorithm will be then guaranteed to find one of +the possible MST's. + +The Kruskal's and Jarn\'\i{}k's algorithms keep working. This is however not the case of the +Bor\o{u}vka's algorithm, whose proof of correctness in Lemma \ref{borcorr} explicitly referred to +distinct weights and indeed, if they are not distinct, the algorithm will occasionally produce +cycles. To avoid the cycles, the ties in edge weight comparisons have to be broken in a~systematic +way. The same applies to the contractive version of this algorithm. + \endpart