]> mj.ucw.cz Git - saga.git/commitdiff
Corrections to the intro to dynamic algorithms.
authorMartin Mares <mj@ucw.cz>
Wed, 9 Apr 2008 16:44:45 +0000 (18:44 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 9 Apr 2008 16:44:45 +0000 (18:44 +0200)
dyn.tex
mst.tex

diff --git a/dyn.tex b/dyn.tex
index 279cfb30e7acdd8965ce02c95c1f92a0523df0df..efa1f24bab9baa7d8465cab3d076c5a34a4ac387 100644 (file)
--- a/dyn.tex
+++ b/dyn.tex
@@ -11,20 +11,19 @@ of graphs that differ only a~little, so recomputing the solution from scratch fo
 every graph would be a~waste of time. In such cases, we usually turn our attention
 to \df{dynamic graph algorithms.} A~dynamic algorithm is in fact a~data structure
 that remembers a~graph and offers operations that modify the structure of the graph
-(let's say by insertion and deletion of edges) and also operations that query the
-result of the problem for the current state of the graph.
-A~typical example of a~problem solved by such algorithms is dynamic maintenance of
-connected components:
+and also operations that query the result of the problem for the current state
+of the graph. A~typical example of a~problem of this kind is dynamic
+maintenance of connected components:
 
 \problemn{Dynamic connectivity}
 Maintain an~undirected graph under a~sequence of the following operations:
 \itemize\ibull
 \:$\<Init>(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.}
+but this is easy to add and infrequently used, so we will rather keep the set
+of vertices fixed for clarity.}
 \:$\<Insert>(G,u,v)$ --- Insert an~edge $uv$ to~$G$ and return its unique
-identifier (assuming that the edge did not exist yet).
+identifier. This assumes that the edge did not exist yet.
 \:$\<Delete>(G,e)$ --- Delete an~edge specified by its identifier from~$G$.
 \:$\<Connected>(G,u,v)$ --- Test if $u$ and~$v$ are in the same connected component of~$G$.
 \endlist
@@ -33,15 +32,16 @@ identifier (assuming that the edge did not exist yet).
 We have already encountered a~special case of dynamic connectivity when implementing the
 Kruskal's algorithm in Section \ref{classalg}. At that time, we did not need to delete
 any edges from the graph, which makes the problem substantially easier. This special
-case is sometimes called an~\df{incremental} or \df{semidynamic} graph algorithm.
-We mentioned the Union-Find data structure of Tarjan and van Leeuwen \cite{tarjan:setunion}
-which can be used for that: queries on connectedness translate to \<Find>, edge
-insertions to \<Find> followed by \<Union> if the edge connects two different
-components. This way, a~sequence of $m$~operations starting with an~empty graph
-on $n$~vertices is processed in time $\O(m\timesalpha(m,n))$ and this works even
-on the Pointer Machine. Fredman and Saks \cite{fredman:cellprobe} have proven
-a~matching lower bound in the cell-probe model which is stronger than RAM with
-$\O(\log n)$-bit words.
+case is customarily called an~\df{incremental} or \df{semidynamic} graph algorithm.
+We mentioned the Disjoint Set Union data structure of Tarjan and van Leeuwen (Theorem \ref{dfu})
+which can be used for that: Connected components are represented as an~equivalence classes.
+Queries on connectedness translate to \<Find>, edge insertions to \<Find>
+followed by \<Union> if the new edge joins two different components. This way,
+a~sequence of $m$~operations starting with an~empty graph on $n$~vertices is
+processed in time $\O(n+m\timesalpha(m,n))$ and this holds even for the Pointer
+Machine. Fredman and Saks \cite{fredman:cellprobe} have proven a~matching lower
+bound in the cell-probe model which is stronger than RAM with $\O(\log n)$-bit
+words.
 
 The edges that have triggered the \<Union>s form a~spanning forest of the current graph.
 So far, all known algorithms for dynamic connectivity maintain some sort of a~spanning
@@ -54,10 +54,10 @@ We however have to answer one important question first: What should be the outpu
 our MSF data structure? Adding an~operation that would return the MSF of the current
 graph is of course possible, but somewhat impractical as this operation has to
 spend $\Omega(n)$ time on the mere writing of its output. A~better way seems to
-be to make the \<Insert> and \<Delete> operations report the list of modifications
-of the MSF caused by the change in the graph.
+be making the \<Insert> and \<Delete> operations report the list of modifications
+of the MSF implied by the change in the graph.
 
-Let us see what happens when we \<Insert> an~edge~$e$ to a~graph~$G$ with a~minimum spanning
+Let us see what happens when we \<Insert> an~edge~$e$ to a~graph~$G$ with its minimum spanning
 forest~$F$, obtaining a~new graph~$G'$ with its MSF~$F'$. If $e$~connects two components of~$G$ (and
 therefore also of~$F$), we have to add~$e$ to~$F$. Otherwise, one of the following cases happens:
 Either $e$~is $F$-heavy and so the forest~$F$ is also the MSF of the new graph. Or it is $F$-light
@@ -68,24 +68,25 @@ Correctness of the former case follows immediately from the Theorem on Minimalit
 minimum. In the latter case, the edge~$f$ is not contained in~$F'$ because it is the heaviest
 on the cycle $F[e]+e$ (by the Red lemma, \ref{redlemma}). We can now use the Blue lemma
 (\ref{bluelemma}) to prove that it should be replaced with~$e$. Consider the tree~$T$
-of~$F$ containing both endpoints of the edge~$e$. When we remove~$f$ from~$F$, this tree falls
+of~$F$ that contains both endpoints of the edge~$e$. When we remove~$f$ from~$F$, this tree falls
 apart to two components $T_1$ and~$T_2$. The edge~$f$ was the lightest edge of the cut~$\delta_G(T_1)$
 and $e$~is lighter than~$f$, so $e$~is the lightest in~$\delta_{G'}(T_1)$ and hence $e\in F'$.
 
 A~\<Delete> of an~edge that is not contained in~$F$ does not change~$F$. When we delete
 an~MSF edge, we have to reconnect~$F$ by choosing the lightest edge of the cut separating
-the new components. If there is no such replacement edge, we have deleted a~bridge,
-so the MSF has to remain disconnected.
+the new components (again the Blue lemma in action). If there is no such
+replacement edge, we have deleted a~bridge, 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 and use it to define the dynamic MSF.
+what we have shown in the following lemma and use it to define the dynamic MSF.
 
 \lemma
 An~\<Insert> or \<Delete> 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)
+Maintain an~undirected graph with distinct weights on edges (drawn from a~totally ordered set)
 and its minimum spanning forest under a~sequence of the following operations:
 \itemize\ibull
 \:$\<Init>(n)$ --- Create a~graph with $n$~isolated vertices $\{1,\ldots,n\}$.
@@ -96,7 +97,7 @@ and its minimum spanning forest under a~sequence of the following operations:
 \endlist
 
 \paran{Semidynamic MSF}%
-To obtain a~semidynamic MSF algorithm, we need to keep the forest in a~data structure which
+To obtain a~semidynamic MSF algorithm, we need to keep the forest in a~data structure that
 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:
 
@@ -111,13 +112,13 @@ as they are not needed in our application.}
 \:$\<Root>(v)$ --- Return the root of the tree containing~$v$.
 \:$\<Weight>(v)$ --- Return the weight of the edge $(\<Parent(v)>,v)$.
 \:$\<PathMax>(v)$ --- Return the vertex~$w$ closest to $\<Root>(v)$ such that the edge
-       $(\<Parent>(w),w)$ is the heaviest of those on the path from~$v$ to the root.
+       $(\<Parent>(w),w)$ is the heaviest of those on the path from the root to~$v$.
        If more edges have the maximum weight, break the tie arbitrarily.
        If there is no such edge ($v$~is the root itself), return \<null>.
 \:$\<Link>(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.
 \:$\<Cut>(v)$ --- Split the tree containing the non-root vertex $v$ to two trees by
-       removing the edge $(v,\<Parent>(v))$. Returns the weight of this edge.
+       removing the edge $(\<Parent>(v),v)$. Returns the weight of this edge.
 \:$\<Evert>(v)$ --- Modify the orientations of the edges in the tree containing~$v$
        to make~$v$ the tree's root.
 \endlist
@@ -139,7 +140,7 @@ See \cite{sleator:trees}.
 \qed
 
 Once we have this structure, we can turn our ideas on updating of the MSF to
-an~algorithm:
+an~incremental algorithm:
 
 \algn{\<Insert> in a~semidynamic MSF}
 \algo
@@ -149,18 +150,18 @@ with weight~$w$ to be inserted.
 \:If $\<Root>(v) \ne u$: \cmt{$u$~and~$v$ lie in different trees.}
 \::$\<Link>(u,v,w)$. \cmt{Connect the trees.}
 \::Return ``$uv$ added''.
-\:Otherwise:
+\:Otherwise: \cmt{both are in the same tree}
 \::$y\=\<PathMax>(v)$.
-\::$x\=\<Parent>(x)$.  \cmt{Edge~$xy$ is the heaviest on $F[uv]$.}
-\::If $\<Weight>(x) > w$: \cmt{We have to exchange~$xy$ with~$uv$.}
-\:::$\<Cut>(x)$, $\<Evert>(v)$, $\<Link>(v,y,w)$.
+\::$x\=\<Parent>(y)$.  \cmt{Edge~$xy$ is the heaviest on $F[uv]$.}
+\::If $\<Weight>(y) > w$: \cmt{We have to exchange~$xy$ with~$uv$.}
+\:::$\<Cut>(y)$, $\<Evert>(v)$, $\<Link>(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)$
+\thmn{Incremental MSF}
+When only edge insertions are allowed, the dynamic MSF can be maintained in time $\O(\log n)$
 amortized per operation.
 
 \proof
@@ -171,7 +172,7 @@ $\O(\log n)$ each by Theorem \ref{sletar}.
 \rem
 We can easily extend the semidynamic MSF algorithm to allow an~operation commonly called
 \<Backtrack> --- removal of the most recently inserted edge. It is sufficient to keep the
-history of MSF changes in a~stack and reverse the most recent change upon backtrack.
+history of all MSF changes in a~stack and reverse the most recent change upon backtrack.
 
 What are the obstacles to making the structure fully dynamic?
 Deletion of edges that do not belong to the MSF is trivial (we do not
@@ -179,6 +180,9 @@ need to change anything) and so is deletion of bridges (we just remove the bridg
 from the Link-Cut tree, knowing that there is no edge to replace it). The hard part
 is the search for replacement edges after an~edge of the MSF is deleted.
 
+As this very problem has to be solved by algorithms for fully dynamic connectivity,
+we will take a~look on them first.
+
 %--------------------------------------------------------------------------------
 
 \section{Eulerian Tour trees}
diff --git a/mst.tex b/mst.tex
index 9f8a7414bc097bba7a59f91e324daf9408d3e1f2..e931d1da4915fe726b4baa8cb46b7fbc0b4151b9 100644 (file)
--- a/mst.tex
+++ b/mst.tex
@@ -491,7 +491,7 @@ so we perform $\<Union>(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}}%
+\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$~\<Union>s intermixed with $m\ge n$~\<Find>s can be processed in time
 $\O(m\timesalpha(m,n))$, where $\alpha(m,n)$ is a~certain inverse of the Ackermann's function