Ranking and Unranking Restricted Permutations

2025-04-22 0 0 270.84KB 26 页 10玖币
侵权投诉
arXiv:2210.17021v2 [math.CO] 9 Nov 2023
Ranking and Unranking Restricted Permutations
Peter Kagey
November 10, 2023
Abstract
We discuss efficient methods for unranking derangements and m´enage
permutations. That is, we will provide an algorithm to efficiently extract
the k-th earliest such permutation under the lexicographic ordering. We
will show that this problem can be reduced to the problem of computing
the number of restricted permutations with a given prefix, and then we
will use rook theory to solve this counting problem. This has applications
to combinatorics, probability, statistics, and modeling.
1 Overview and preliminaries
In 2020, Richard Arratia announced two $100 prizes with a similar flavor, both
about unranking problems: given a strict total order on a finite set, when is it
possible to directly compute the i-th element with respect to the total order?
Problem 1 ($100 question).For n= 20 there are
895 014 631 192 902 121 >8.9·1017
elements of the set
{πSn|π(i)6=i1in},
which are called derangements.1Determine the 5×1017-th such permutation
when listed in lexicographic order.
Answer 1. The derangement in S20 with rank 5×1017 is
12 14 2 9 13 20 6 3 1 17 5 11 19 15 10 18 8 7 4 16.
The algorithm for computing this permutation will be described in Section 4.
Problem 2 ($100 question).For n= 20 there are
312 400 218 671 253 762 >3.1·1017
elements of the set
{πSn|π(i)6∈ {i1, i}(mod n)1in},
which are called m´enage permutations.2Determine the 1017-th such permutation
1This function is described by sequence A000166 in the On-Line Encyclopedia of Integer
Sequences (OEIS) [4].
2This function is described by sequence A000179 in the OEIS [4].
1
when listed in lexicographic order.
Answer 2. The m´enage permutation in S20 with rank 1017 is
7 16 19 12 2 8 15 1 18 14 3 9 20 10 5 17 13 4 11 6.
The algorithm for computing this value will be described in Section 5.
Example 3. The 44 derangements in S5, ordered lexicographically are.
π1= 21453
π2= 21534
π3= 23154
π4= 23451
π5= 23514
π6= 24153
π7= 24513
π8= 24531
π9= 25134
π10 = 25413
π11 = 25431
π12 = 31254
π13 = 31452
π14 = 31524
π15 = 34152
π16 = 34251
π17 = 34512
π18 = 34521
π19 = 35124
π20 = 35214
π21 = 35412
π22 = 35421
π23 = 41253
π24 = 41523
π25 = 41532
π26 = 43152
π27 = 43251
π28 = 43512
π29 = 43521
π30 = 45123
π31 = 45132
π32 = 45213
π33 = 45231
π34 = 51234
π35 = 51423
π36 = 51432
π37 = 53124
π38 = 53214
π39 = 53412
π40 = 53421
π41 = 54123
π42 = 54132
π43 = 54213
π44 = 54231
In particular, unranking the 19th derangement in S5gives 35214; alterna-
tively, ranking the derangement 43251 gives 26.
To be explicit about what we wish to compute efficiently, we define the
notion of a unranking.
Definition 4. Let Cbe a finite set with a strict total order, and let {ci}|C|
i=1 be
the unique sequence of elements in Csuch that ci< ci+1 for all 1i < |C|.
Then a unranking is a map
unrankC:{1,2,...,|C|} → C
that sends i7→ ci.
An efficient algorithm to unrank a collection of objects implies an efficient
algorithm for sampling from the collection uniformly at random by sampling
the indices uniformly at random. This can be of use in the case of Monte Carlo
simulations and other instances where it is useful to be able to sample uniformly
from a collection of combinatorial objects.
As the name suggests, every unranking problem comes with a dual problem
called the ranking problem.”
Definition 5. Aranking of a nite set Cwith a strict total order is a map
rankC:C→ {1,2,...,|C|}
that sends ci7→ i.
2
The existence of both efficient ranking and unranking maps implies the ex-
istence of an efficient encoding for these objects, which may be of interest to
computer scientists. The encoding works by ranking an object to get its index,
which then can be stored in as a positive integer and unranked on retrieval to
recover the original object.
In the remaining sections, we will show how we resolved both of the above
problems in order to claim Richard Arratia’s two $100 prizes. In particular, we
will construct an algorithm for ranking and unranking both derangements and
m´enage permutations under the lexicographic ordering. We will show that the
existence of an efficient way to count the number of such permutations with a
given prefix implies that there is an efficient way to compute the ranking and
unranking maps. Then we will develop some ideas from rook theory and apply
them to the context of derangements and m´enage permutations.
2 Prefix counting and word ranking
In both the case of unranking derangements and menage permutations (and in
many other applications) our combinatorial objects are words in lexicographic
order, which is a generalization of alphabetical order.
We begin by developing a general theory for unranking collections of words
in lexicographic order by counting the number of words with a given prefix.
2.1 Words with a given prefix
We will start by introducing some basic definitions about words and prefixes,
and to formalize the notion of lexicographic order.
Definition 6. A finite word wover an alphabet Ais a finite sequence {wi
A}N
i=1.
The collection of finite words over the alphabet Ais denoted by WA, or just
Wwhen the alphabet is implicit from context.
Definition 7. A word w={wiA}N
i=1 is said to begin with a prefix αof
length Mif MN,α={αiA}M
i=1, and wi=αifor all iM.
Definition 8. A word wis said to be before win lexicographic order if
either wis a proper prefix of w, or if at the first position, i, where wand w
differ, wi< w
i.
With these definitions established, we can turn the problem of unranking
words into a problem about counting words with specified prefixes.
Theorem 9. For k > 0, let Wbe a set of nonempty words on the alphabet
[n] = {1,2,...,n}, and let C(Wbe a finite subset of words on this alphabet,
with a total order given by its lexicographic order.
Let #prefixC:WCbe the function that counts the number of words in
Cthat begin with a given prefix.
3
Then the unranking function can be computed recursively by
unrankC(i) = fC
i((1),0) (1)
where
fC
i(α, j) =
fC
i(α, j + #prefixC(α)) i > j + #prefixC(α) (2a)
fC
i(α′′, j)α6∈ Cand ij+ #prefixC(α) (2b)
fC
i(α′′, j + 1) αC,ij+ #prefixC(α),
and i6=j+ 1 (2c)
α α Cand i=j+ 1,(2d)
where
α= (α1, α2,...,α),
α= (α1, α2,...,α1,1 + α),
α′′ = (α1, α2,...,α,1),
and jdenotes the number of words in Cthat occur strictly before α.
Proof. We make three claims that we will prove using induction on the recursive
applications of fC
i(α, j): (1) that jis the number of words in Cthat occur
strictly before α, (2) that αwi, and (3) that the sequence of αs is strictly
increasing.
This final claim (the sequence of αs is strictly increasing) follows from the
observation that α < α′′ < αin lexicographic order.
Because each iteration increases either jor (the number of letters in α) or
both, the number of recursive applications of fC
irequired to determine wiis at
most i+ maxwW|w|, which is finite because Wonly contains of finite words.
The base case is clear: We start with fC
i((1),0) because (1) is the lexico-
graphically earliest word, so 0 nonempty words strictly precede it, and (1) wi.
We will repeatedly use the observation that if jwords precede α, then a
word has prefix αif and only if its index is in (j, j + #prefixC(α)]. Note that
this range is empty whenever there are no words prefixed by α.
Case (2a).Because j+#prefixC(α) is the index of the last word that begins
with α, if i > j + #prefixC(α), then wimust begin with a length-prefix that
is lexicographically later than α.
By construction, αis the lexicographically earliest word of length that
comes after α, therefore αwi. As such, the number of words that strictly
precede αis j+ #prefixC(α), which is the sum of the number of words that
occur strictly before αand the number of words that have prefix α.
Case (2b).If α6∈ Cand ij+#prefixC(α), then αis a proper prefix of wi,
and wiis of length at least + 1. By construction, α′′ is the lexicographically
earliest word of length + 1 that has a prefix of α, so α′′ wi, and the number
4
of words in Cthat precede α′′ is equal to j, the number of words that precede
α.
Case (2c).If αC,ij+ #prefixC(α), and i6=j+ 1 then αmust be the
word at index j+ 1 < i, because αitself is the lexicographically earliest word
with the prefix α. Because words cannot appear multiple times in C,wimust
have αas a proper prefix. Therefore α′′ wiand the number of words that
strictly precede α′′ is j+ 1: the number of words that strictly precede αplus α
itself.
Case (2d).If αCand i=j+ 1, then wi=αbecause αitself is the
lexicographically earliest word with the prefix α, so it must occur at index
i=j+ 1.
Notice that each recursive call of fC
iincreases the sum of the letters of α. If
we suppose that Cis a finite set of words on the alphabet [n] of length at most
k, then unranking a word from C(k)requires at most nk recursive applications
of fC(k)
i.
Therefore if there exists a polynomial time algorithm for computing #prefixC,
then there exists an unranking algorithm that is polynomial in the size of the
alphabet Aand the length of the longest word. In the case of restricted per-
mutations, each of these grow linearly with the number of letters in the enage
permutations.
2.2 Ranking words
Just as we can recursively find a word at a given index, we can also recursively
find a index corresponding to a given word.
Theorem 10. If C(Wis a collection of nonempty words over the alphabet
[n], then the rank of the word wCcan be computed as the sum
rankC(w) =
|w|
X
i=1 C(w(i)) +
wi1
X
=1
#prefixC(w
(i1))!
where
w= (w1, w2,...,w|w|),
w(i)= (w1, w2,...,wi1, wi),
w
(i1) = (w1, w2,...,wi1, ℓ),
and C:W→ {0,1}is the indicator function of C, where C(x) = 1 if and
only if xC.
Proof. Note that the inner sum
C(w(i)) +
wi1
X
=1
#prefixC(w
(i1))
5
摘要:

arXiv:2210.17021v2[math.CO]9Nov2023RankingandUnrankingRestrictedPermutationsPeterKageyNovember10,2023AbstractWediscussefficientmethodsforunrankingderangementsandm´enagepermutations.Thatis,wewillprovideanalgorithmtoefficientlyextractthek-thearliestsuchpermutationunderthelexicographicordering.Wewillshowth...

展开>> 收起<<
Ranking and Unranking Restricted Permutations.pdf

共26页,预览5页

还剩页未读, 继续阅读

声明:本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。玖贝云文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知玖贝云文库,我们立即给予删除!
分类:图书资源 价格:10玖币 属性:26 页 大小:270.84KB 格式:PDF 时间:2025-04-22

开通VIP享超值会员特权

  • 多端同步记录
  • 高速下载文档
  • 免费文档工具
  • 分享文档赚钱
  • 每日登录抽奖
  • 优质衍生服务
/ 26
客服
关注