]> mj.ucw.cz Git - saga.git/commitdiff
Finished Q-heaps.
authorMartin Mares <mj@ucw.cz>
Tue, 4 Mar 2008 14:02:58 +0000 (15:02 +0100)
committerMartin Mares <mj@ucw.cz>
Tue, 4 Mar 2008 14:02:58 +0000 (15:02 +0100)
PLAN
biblio.bib
ram.tex

diff --git a/PLAN b/PLAN
index 0a6af894e366846699d54530e84981aa3fd590fc..f0c63b45fe988cb98c527e1ddd6aaef110bf3f24 100644 (file)
--- a/PLAN
+++ b/PLAN
@@ -64,6 +64,7 @@ Models:
 - bit tricks: reference to HAKMEM
 - mention in-place radix-sorting?
 - consequences of Q-Heaps: Thorup's undirected SSSP etc.
+- add more context from thorup:aczero, also mention FP operations
 - refs on Cartesian trees
 - update notation.tex
 - iteration of Q-Heaps
index d8ba9658952d72bc3a1cde2f068e4f75cc3fa13e..7d96bc0959cb62cd35d37e24dc84b3b87407b79a 100644 (file)
@@ -870,3 +870,14 @@ inproceedings{ pettie:minirand,
   pages={75--86},
   year={2005}
 }
+
+@article{ andersson:fusion,
+  title={{Fusion trees can be implemented with AC0 instructions only}},
+  author={Andersson, A. and Miltersen, P.B. and Thorup, M.},
+  journal={Theoretical Computer Science},
+  volume={215},
+  number={1-2},
+  pages={337--344},
+  year={1999},
+  publisher={Elsevier}
+}
diff --git a/ram.tex b/ram.tex
index db6fd5a68d247c0967e97905fa370b4ebced144f..a261545635931b95a0e0c21387cd26366b5251a7 100644 (file)
--- a/ram.tex
+++ b/ram.tex
@@ -878,7 +878,7 @@ A~\df{Q-heap} consists of:
 \:precomputed tables of various functions.
 \endlist
 
-\algn{Search in the Q-heap}
+\algn{Search in the Q-heap}\id{qhfirst}%
 \algo
 \algin A~Q-heap and an~integer~$x$ to search for.
 \:$i\=R_X(x)+1$, using Lemma~\ref{qhrank} to calculate the rank.
@@ -893,7 +893,7 @@ A~\df{Q-heap} consists of:
 \:If $x=x_i$, return immediately (the value is already present).
 \:Insert the new value to~$X$:
 \::$n\=n+1$
-\::$X[n]\=x$ and insert~$r$ at the $i$-th position in the permutation~$\varrho$.
+\::$X[n]\=x$ and insert~$n$ at the $i$-th position in the permutation~$\varrho$.
 \:Update the $g_j$'s:
 \::Move all~$g_j$ for $j\ge i$ one position up. \hfil\break
    This translates to insertion in the vector representing~$G$.
@@ -915,7 +915,7 @@ A~\df{Q-heap} consists of:
 \algout The updated Q-heap.
 \endalgo
 
-\algn{Finding the $i$-th smallest element in the Q-heap}
+\algn{Finding the $i$-th smallest element in the Q-heap}\id{qhlast}%
 \algo
 \algin A~Q-heap and an~index~$i$.
 \:If $i<1$ or $i>n$, return {\sc undefined.}
@@ -923,4 +923,48 @@ A~\df{Q-heap} consists of:
 \algout The $i$-th smallest element in the heap.
 \endalgo
 
+\para
+The heap algorithms we have just described have been built from primitives
+operating in constant time, with one notable exception: the extraction
+$x[B]$ of all bits of~$x$ at positions specified by the set~$B$. This cannot be done
+in~$\O(1)$ time on the Word-RAM, but we can implement it with ${\rm AC}^0$
+instructions as suggested by Andersson in \cite{andersson:fusion} or even
+with those ${\rm AC}^0$ instructions present on real processors (see Thorup
+\cite{thorup:aczero}). On the Word-RAM, we need to make use of the fact
+that the set~$B$ is not changing too much --- there are $\O(1)$ changes
+per Q-heap operation. As Fredman and Willard have shown, it is possible
+to maintain a~``decoder'', whose state is stored in $\O(1)$ machine words,
+and which helps us to extract $x[B]$ in a~constant number of operations:
+
+\lemman{Extraction of bits, Fredman and Willard \cite{fw:transdich}}\id{qhxtract}%
+Under the assumptions on~$k$, $W$ and the preprocessing time as in the Q-heaps,
+it is possible to maintain a~data structure for a~set~$B$ of bit positions,
+which allows~$x[B]$ to be extracted in $\O(1)$ time for an~arbitrary~$x$.
+When a~single element is inserted to~$B$ or deleted from~$B$, the structure
+can be updated in constant time, as long as $\vert B\vert \le k$.
+
+\proof
+See Fredman and Willard \cite{fw:transdich}.
+\qed
+
+\para
+This was the last missing bit of the mechanics of the Q-heaps. We are
+therefore ready to conclude this section by the following theorem:
+
+\thmn{Q-heaps, Fredman and Willard \cite{fw:transdich}}\id{qh}%
+Let $W$ and~$k$ be positive integers such that $k=\O(W^{1/4})$. Let~$Q$
+be a~Q-heap of at most $k$-elements of $W$~bits each. Then the Q-heap
+operations \ref{qhfirst} to \ref{qhlast} on~$Q$ (insertion, deletion,
+search for a~given value and search for the $i$-th smallest element)
+run in constant time on a~Word-RAM with word size~$W$, after spending
+time $\O(2^{k^4})$ on the same RAM by precomputing of tables.
+
+\proof
+Every operation on the Q-heap can be performed in a~constant number of
+vector operations and calculations of ranks. The ranks are computed
+in $\O(1)$ steps involving again $\O(1)$ vector operations, binary
+logarithms and bit extraction. All these can be calculated in constant
+time using the results of section \ref{bitsect} and Lemma \ref{qhxtract}.
+\qed
+
 \endpart