From: Martin Mares Date: Fri, 22 Feb 2008 13:31:29 +0000 (+0100) Subject: Reformulate the trick for k-permutations. X-Git-Tag: printed~233 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=99cb216525ff987b4ef68ed2925b608a23cdd47d;p=saga.git Reformulate the trick for k-permutations. --- diff --git a/rank.tex b/rank.tex index 2a62859..da67a9f 100644 --- a/rank.tex +++ b/rank.tex @@ -250,28 +250,27 @@ To calculate $R_H(x)$, we can again use the vector operation \ from Algori this time on the vector~$\bf h$. The only operation we cannot translate directly is unranking in~$A$. We will -therefore define an~auxiliary vector~$\bf b$ of the same size as~$\bf h$, -such that $b_i=h_i-i$ (this is the number of elements of~$A$ smaller -than~$h_i$). Now, if we want to find the $r$-th smallest element of~$A$, we find -the largest $i$ such that $b_i(r,j+1)-1$. Finding the right element in the interval +is then easy: $R^{-1}_A(j) = h_i + 1 + j - r_i$. \example -If $A=\{2,5,6\}$ and $n=8$, then ${\bf h}=(1,3,4,7,8)$ and ${\bf b} -= (0,1,1,3,3)$. When we want to calculate $R^{-1}_A(2)$, we find $i=3$ and we -get $g_3+1+2-b_3 = 4+1+2-1 = 6$. +If $A=\{2,5,6\}$ and $n=8$, then ${\bf h}=(1,3,4,7,8)$ and ${\bf r} += (0,1,1,3,3)$. When we want to calculate $R^{-1}_A(2)$, we find $i=2$ and +the wanted element is $h_2+1+2-r_2 = 4+1+2-1 = 6$. \para -The vector~$\bf b$ can be updated in constant time whenever an~element is +The vector~$\bf r$ can be updated in constant time whenever an~element is inserted to~$\bf h$. It is sufficient to shift the fields apart (we know -that the position of the new element in~$\bf b$ is the same as in~$\bf h$), +that the position of the new element in~$\bf r$ is the same as in~$\bf h$), insert the new value using masking operations and decrease all higher fields by one in parallel by using a~single subtraction. Updates after deletions from~$\bf h$ are analogous. -\FIXME{State the algorithms properly.} - We have replaced all operations on~$A$ by the corresponding operations on the modified data structure, each of which works again in constant time. Therefore we have just proven the following theorem, which brings this section to @@ -282,10 +281,11 @@ When we order the $k$-per\-mu\-ta\-tions on the set~$[n]$ lexicographically, bot ranking and unranking can be performed on the RAM in time~$\O(k)$. \proof -We modify algorithms \ref{rankalg} and \ref{unrankalg} as described in this section. -The modified data structure performs all required operations on the set~$A$ in -constant time. The depth of the recursion is $\O(k)$ and we spend $\O(1)$ time -at every level. The time bound follows. -\qed +We modify algorithms \ref{rankalg} and \ref{unrankalg} for $k$-permutations as +shown at the beginning of this section. We use the vectors $\bf h$ and~$\bf r$ +described above as an~implicit representation of the set~$A$. The modified +algorithm uses recursion $k$~levels deep and as each operation on~$A$ can be +performed in~$\O(1)$ time using $\bf h$ and~$\bf r$, every level takes only +constant time. The time bound follows. \qed \endpart