From: Martin Mares Date: Wed, 9 Apr 2008 08:15:34 +0000 (+0200) Subject: Semidynamic MSF. X-Git-Tag: printed~110 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=e06622aee7d6c553e34f5446db1dce0029025d70;p=saga.git Semidynamic MSF. --- diff --git a/PLAN b/PLAN index 837118b..050f0ea 100644 --- a/PLAN +++ b/PLAN @@ -32,7 +32,6 @@ * Dynamic MST algorithms . (Semi-)dynamic algorithms - . Sleator-Tarjan trees and semi-dynamic MST . ET-trees . Fully dynamic connectivity . Dynamic MST @@ -73,10 +72,14 @@ Models: - mention in-place radix-sorting? - consequences of Q-Heaps: Thorup's undirected SSSP etc. - add more context from thorup:aczero, also mention FP operations -- Tarjan79 is claimed by Pettie to define Pointer machines +- Tarjan79 is mentioned by Pettie to define Pointer machines - add references to the C language - PM: unify yardsticks +Dynamic: + +- What is the origin of the semidynamic MSF? + Ranking: - the general perspective: is it only a technical trick? diff --git a/dyn.tex b/dyn.tex index ea51c44..502f618 100644 --- a/dyn.tex +++ b/dyn.tex @@ -19,14 +19,14 @@ connected components: \problemn{Dynamic connectivity} Maintain an~undirected graph under a~sequence of the following operations: \itemize\ibull -\:$\(n)$ --- create a~graph with $n$~isolated vertices $\{1,\ldots,n\}$,\foot{% +\:$\(n)$ --- Create a~graph with $n$~isolated vertices $\{1,\ldots,n\}$.\foot{% The structure could support dynamic addition and removal of vertices, too, but this is easy to add and infrequently used, so we will rather define the structure with a~fixed set of vertices for clarity.} -\:$\(G,u,v)$ --- insert an~edge $uv$ to~$G$ and return its unique -identifier (assuming that the edge did not exist yet), -\:$\(G,e)$ --- delete an~edge specified by its identifier from~$G$, -\:$\(G,u,v)$ --- test if $u$ and~$v$ are in the same connected component of~$G$. +\:$\(G,u,v)$ --- Insert an~edge $uv$ to~$G$ and return its unique +identifier (assuming that the edge did not exist yet). +\:$\(G,e)$ --- Delete an~edge specified by its identifier from~$G$. +\:$\(G,u,v)$ --- Test if $u$ and~$v$ are in the same connected component of~$G$. \endlist \para @@ -47,8 +47,8 @@ The edges that have triggered the \s form a~spanning forest of the curren So far, all known algorithms for dynamic connectivity maintain some sort of a~spanning tree. This suggests that a~dynamic MST algorithm could be obtained by modifying the dynamic connectivity algorithms. This will indeed turn out to be true. Semidynamic MST -is easy to achieve before the end of this section, but making it fully dynamic will require -more effort, so we will review some of the existing data structures in the meantime. +is easy to achieve even in the few pages of this section, but making it fully dynamic will require +more effort, so we will review some of the required building blocks before going into that. We however have to answer one important question first: What should be the output of our MSF data structure? Adding an~operation that would return the MSF of the current @@ -78,28 +78,95 @@ the new components. If there is no such replacement edge, we have deleted a~brid so the MSF has to remain disconnected. The idea of reporting differences in the MSF indeed works very well. We can summarize -what we have shown by the following lemma: +what we have shown by the following lemma and use it to define the dynamic MSF. \lemma An~\ or \ of an~edge in~$G$ causes at most one edge addition, edge removal or edge exchange in $\msf(G)$. +\problemn{Dynamic minimum spanning forest} +Maintain an~undirected graph with weights on edges (drawn from a~totally ordered set) +and its minimum spanning forest under a~sequence of the following operations: +\itemize\ibull +\:$\(n)$ --- Create a~graph with $n$~isolated vertices $\{1,\ldots,n\}$. +\:$\(G,u,v)$ --- Insert an~edge $uv$ to~$G$. Return its unique + identifier and the list of additions and deletions of edges in $\msf(G)$. +\:$\(G,e)$ --- Delete an~edge specified by its identifier from~$G$. + Return the list of additions and deletions of edges in $\msf(G)$. +\endlist + \paran{Semidynamic MSF}% To obtain a~semidynamic MSF algorithm, we need to keep the forest in a~data structure which supports search for the heaviest edge on the path connecting a~given pair of vertices. This can be handled efficiently by the Link-Cut trees of Sleator and Tarjan: -\thmn{Link-Cut Trees, Sleator and Tarjan \cite{sleator:trees}} +\thmn{Link-Cut Trees, Sleator and Tarjan \cite{sleator:trees}}\id{sletar}% There is a~data structure that represents a~forest of rooted trees on~$n$ vertices. Each edge of the forest has a~weight drawn from a~totally ordered set. The structure -supports the following operations in time $\O(\log n)$ amortized: +supports the following operations in time $\O(\log n)$ amortized:\foot{% +The Link-Cut trees offer many other operations, but we do not mention them +as they are not needed in our application.} +\itemize\ibull +\:$\(v)$ --- Return the parent of~$v$ in its tree or \ if $v$~is a~root. +\:$\(v)$ --- Return the root of the tree containing~$v$. +\:$\(v)$ --- Return the weight of the edge $(\,v)$. +\:$\(v)$ --- Return the vertex~$w$ closest to $\(v)$ such that the edge + $(\(w),w)$ is the heaviest of those on the path from~$v$ to the root. + If more edges have the maximum weight, break the tie arbitrarily. + If there is no such edge ($v$~is the root itself), return \. +\:$\(u,v,x)$ --- Connect the trees containing $u$ and~$v$ by an~edge $(u,v)$ of + weight~$x$. Assumes that $u~$is a tree root and $v$~lies in a~different tree. +\:$\(v)$ --- Split the tree containing the non-root vertex $v$ to two trees by + removing the edge $(v,\(v))$. Returns the weight of this edge. +\:$\(v)$ --- Modify the orientations of the edges in the tree containing~$v$ + to make~$v$ the tree's root. +\endlist -XXX +%% \>Additionally, all edges on the path from~$v$ to $\(v)$ can be enumerated in +%% time $\O(\ell + \log n)$, where $\ell$~is the length of that path. This operation +%% (and also the path itself) is called $\(v)$. +%% +%% \>If the weights are real numbers (or in general an~arbitrary group), the $\O(\log n)$ +%% operations also include: +%% +%% \itemize\ibull +%% \:$\(v)$ --- Return the sum of the weights on $\(v)$. +%% \:$\(v,x)$ --- Add~$x$ to the weights of all edges on $\(v)$. +%% \endlist \proof See \cite{sleator:trees}. \qed +Once we have this structure, we can turn our ideas on updating of the MSF to +an~algorithm: + +\algn{\ in a~semidynamic MSF} +\algo +\algin A~graph~$G$ with its MSF $F$ represented as a~Link-Cut forest, an~edge~$uv$ +with weight~$w$ to be inserted. +\:$\(u)$. \cmt{$u$~is now the root of its tree.} +\:If $\(v) \ne u$: \cmt{$u$~and~$v$ lie in different trees.} +\::$\(u,v,w)$. \cmt{Connect the trees.} +\::Return ``$uv$ added''. +\:Otherwise: +\::$y\=\(v)$. +\::$x\=\(x)$. \cmt{Edge~$xy$ is the heaviest on $F[uv]$.} +\::If $\(x) > w$: \cmt{We have to exchange~$xy$ with~$uv$.} +\:::$\(x)$, $\(v)$, $\(v,y,w)$. +\:::Return ``$uv$~added, $xy$~removed''. +\::Otherwise return ``no changes''. +\algout The list of changes in~$F$. +\endalgo + +\thmn{Semidynamic MSF} +When only edge insertions are allowed, the MSF can be maintained in time $\O(\log n)$ +amortized per operation. + +\proof +Every \ performs $\O(1)$ operations on the Link-Cut forest, which take +$\O(\log n)$ each by Theorem \ref{sletar}. +\qed %-------------------------------------------------------------------------------- diff --git a/opt.tex b/opt.tex index 15b97d5..7d236c6 100644 --- a/opt.tex +++ b/opt.tex @@ -27,13 +27,13 @@ corrupted. The soft heap contains a~set of distinct items from a~totally ordered universe and it supports the following operations: \itemize\ibull -\:$\(\varepsilon)$ --- create an~empty soft heap with the given accuracy parameter~$\varepsilon$, -\:$\(H,x)$ --- insert a~new item~$x$ to the heap~$H$, -\:$\(P,Q)$ --- merge two heaps into one, more precisely move all items of a~heap~$Q$ - to the heap~$P$, destroying~$Q$ in the process (both heaps must have the same~$\varepsilon$), -\:$\(H)$ --- delete the minimum item of the heap~$H$ and return its value +\:$\(\varepsilon)$ --- Create an~empty soft heap with the given accuracy parameter~$\varepsilon$. +\:$\(H,x)$ --- Insert a~new item~$x$ to the heap~$H$. +\:$\(P,Q)$ --- Merge two heaps into one, more precisely move all items of a~heap~$Q$ + to the heap~$P$, destroying~$Q$ in the process (both heaps must have the same~$\varepsilon$). +\:$\(H)$ --- Delete the minimum item of the heap~$H$ and return its value (optionally signalling that the value has been corrupted). -\:$\(H)$ --- destroy the heap and return a~list of all items contained in it +\:$\(H)$ --- Destroy the heap and return a~list of all items contained in it (again optionally marking those corrupted). \endlist