From: Martin Mares Date: Tue, 4 Mar 2008 14:02:58 +0000 (+0100) Subject: Finished Q-heaps. X-Git-Tag: printed~200 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=07909612545b662d9a5cc696a52968b1ab3d2fa2;p=saga.git Finished Q-heaps. --- diff --git a/PLAN b/PLAN index 0a6af89..f0c63b4 100644 --- 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 diff --git a/biblio.bib b/biblio.bib index d8ba965..7d96bc0 100644 --- a/biblio.bib +++ b/biblio.bib @@ -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 db6fd5a..a261545 100644 --- 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