From 2eb7de659ad40307694b7f264b2ba4a9ea204cba Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 27 Feb 2008 20:40:34 +0100 Subject: [PATCH] Finished derangements. --- rank.tex | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/rank.tex b/rank.tex index 8df70ca..60a3be2 100644 --- a/rank.tex +++ b/rank.tex @@ -648,7 +648,16 @@ permutations $(\pi[2],\ldots,\pi[d])$ on $\{2,\ldots,d\}$ which satisfy~$M_z^{1, so there are $n_0(z-1,d-1)$ of them. \qed -\cor For every $0\le z function now run in constant time, +but \ needs to search among the~$C_a$'s to find the first of them which +exceeds the given rank. We could use binary search, but that would take $\Theta(\log n)$ +time. There is however a~clever trick: the value of~$C_a$ does not vary too much with +the set~$Z$. Specifically, by Corollary~\ref{smalldiff} the difference between the values +for $Z=\emptyset$ and $Z=A$ is at most $n_0(z-1,\vert A\vert -1)$. It is therefore +sufficient to just divide the rank by $n_0(z-1,\vert A\vert-1)$ and we get either +the correct value of~$a$ or one more. Both possibilities can be checked in constant time. + +We can therefore conclude this section by the following theorem: + +\thmn{Ranking of derangements}% +For every~$n$, the derangements on the set~$[n]$ can be ranked and unranked according to the +lexicographic order in time~$\O(n)$ after spending $\O(n^2)$ on initialization of auxiliary tables. + +\proof +We modify the general algorithms for (un)ranking of restricted permutations (\ref{rrankalg} and \ref{runrankalg}) +as described above (\ref{rrankmod}). Each of the $n$~levels of recursion will then run in constant time. The values~$n_0$ will +be looked up in a~table precalculated in quadratic time as shown in Corollary~\ref{nzeroprecalc}. +\qed -- 2.39.2