• Aucun résultat trouvé

Generating random alternating permutations in time $n\log n$

N/A
N/A
Protected

Academic year: 2021

Partager "Generating random alternating permutations in time $n\log n$"

Copied!
8
0
0

Texte intégral

(1)

HAL Id: hal-00765432

https://hal.archives-ouvertes.fr/hal-00765432

Preprint submitted on 14 Dec 2012

HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires

Generating random alternating permutations in time n log n

Philippe Marchal

To cite this version:

Philippe Marchal. Generating random alternating permutations in time n log n. 2012. �hal-00765432�

(2)

Generating random alternating permutations in time n log n

P. Marchal

Universit´e Paris 13 Sorbonne Paris Cit´e

LAGA CNRS (UMR 7539) F-93430, Villetaneuse marchal@math.univ-paris13.fr

Abstract

We introduce an algorithm generating uniformly distributed random alternating permutations of length n in time n log n .

1 The main result

An alternating permutation σ of {1, 2, . . . N} is a permutation such that σ(1) > σ(2) < σ(3) > σ(4) . . .

Alternating permutations are a very classical topic in combinatorics. See for instance the survey [ST] for numerous references. The basic result, which dates back from the 19th century [A], states that if p N is the probability that a permutation of {1, 2, . . . N} chosen uniformly at random is alternating, then

X

N ≥0

p N x N = sec x + tan x

The integers N !p N are called Euler numbers. The goal of this paper is to intro- duce an algorithm generating random alternating permutations of {1, 2, . . . N}

in time N log N .

An alternative way to generate random alternating permutations is to use

Boltzmann sampling [DFLS]. In a general framework, this method constructs

random combinatorial objects of approximate size in linear time. However, to

get the exact size, one must use a rejection procedure and the complexity of the

algorithm increases. In the context of permutations, the average time to run

the algorithm is quadratic in the length of the permutation.

(3)

Before describing our algorithm, we begin by a simple remark. Let Y = (Y 1 , . . . Y N ) be a sequence of distinct reals in [0, 1]. We can construct from Y a permutation as follows. Let k 1 ∈ {1, 2, . . . N } be the integer such that Y k

1

is minimal in {Y 1 , . . . Y N } and put σ(k 1 ) = 1. Then, let k 2 ∈ {1, 2, . . . N } − {k 1 } be the integer such that Y k

2

is minimal in {Y 1 , . . . Y N } − {Y k

1

}, put σ(k 2 ) = 2 and so on. To recover σ from Y , one can use a sorting algorithm.

If the sequence is alternating, that is, if Y 1 > Y 2 < Y 3 > Y 4 . . .

then σ is alternating. Besides, if Y is chosen according to the Lebesgue mea- sure on [0, 1] N +1 , then σ is uniformly distributed over all permutations of {1, 2, . . . N}. As a consequence, if Y is a random, uniform alternating sequence, that is, if its density with respect to the Lebesgue measure on [0, 1] N +1 is

(1/p N )1 {Y

1

>Y

2

<Y

3

>Y

4

...} (1) then σ is uniformly distributed over all alternating permutations. Therefore, we want to find an algorithm constructing a random, uniform alternating sequence.

Remark that with probability 1, all the reals in the sequence will be distinct.

Algorithm

Fix an integer N and let U 1 , U 2 , . . . U N be iid random variables, uniformly distributed on [0, 1]. First, define a random sequence (X 1 , . . . , X N ) as follows:

• X 1 = U 1

• for n ∈ [1, N − 1],

X n+1 = 1 − 2

π arcsin

U n+1 sin( π 2 X n ) Next, put

α N = sin( π 2 X N )

sin( π 2 X 1 ) (2)

and define the sequence Y as follows

• With probability 1/(α N + α −1 N ), put

Y = (X 1 , 1 − X 2 , X 3 , 1 − X 4 . . .)

• With probability 1/(α N + α −1 N ), put

Y = (X N , 1 − X N−1 , X N −2 , 1 − X N−3 . . .)

• With probability 1 − 2/(α N + α −1 N ), start over.

Finally, recover a permutation from Y by randomized quicksort.

(4)

Theorem 1 The algorithm described above yields a random alternating permu- tation of {1, 2, . . . N}, uniformly distributed over all alternating permutations.

The rejection probability is bounded above, uniformly on N, by E[1 − 2/(α N + α −1 N )] ≤ 7

8 As a consequence, the average complexity is Θ(N log N ).

The upper bound on the rejection probability is certainly not optimal, how- ever, it is sufficient for our purpose. We now proceed to the proof of the theorem.

2 Proof of the result

First, let us observe that the random sequence X is a Markov chain. Let us compute its transition probabilities. Let x ∈ [0, 1] and n ≥ 1. With probability x, U n ≤ 1 − x and therefore, conditionally on X n , with probability x,

X n+1 ≥ 1 − 2

π arcsin

(1 − x) sin( π 2 X n )

In other words, the right-hand side of the inequality above is the inverse of F n+1 , where F n+1 stands for the cumulative distribution function of X n+1 , conditionally on X n . Therefore F n+1 (x) = 0 for x ≤ 1 −X n and for x ≥ 1 − X n ,

F n+1 (x) = 1 − sin( π 2 (1 − x))

sin( π 2 X n ) = 1 − cos( π 2 x) sin( π 2 X n )

Differentiating, we find that the conditional density of X n+1 given X n is f X

n

, with

f x (y) = 1 {y≥1−x} π 2

sin( π 2 y) sin( π 2 x) To sum up, the transition probabilities of X are given by

P x (X 2 ∈ dy) = f x (y)dy

where, as usual, P x denotes the probability for the Markov chain started at x.

As a consequence, the density of X with respect to the Lebesgue measure on [0, 1] N+1 is

1 {X

2

≥1−X

1

,X

3

≥1−X

2

,...}

π 2

N−1 sin( π 2 X N ) sin( π 2 X 1 )

= 1 {X

2

≥1−X

1

,X

3

≥1−X

2

,...}

π 2

N−1

α N

with α N defined in (2). Likewise, the density of (X N , X N− 1 , X N − 2 , X N− 3 . . .) with respect to the Lebesgue measure on [0, 1] N +1 is

1 {X

2

≥1−X

1

,X

3

≥1−X

2

,...}

π 2

N −1

α −1 N

(5)

Now define a random sequence Z as follows. With probability 1/(α N + α −1 N ), put

Z = (X 1 , X 2 , X 3 . . .) With probability 1/(α N + α −1 N ), put

Z = (X N , X N −1 , X N−2 , . . .)

Since Z is obtained either by keeping X or by taking its time reversal, its density is a convex combination of the density of X and of the density of the time-reversal of X. More precisely, the density of Z with respect to the Lebesgue measure on [0, 1] N +1 is given by

1 {Z

2

≥1−Z

1

,Z

3

≥1−Z

2

,...}

π 2

N− 1 α N

α N + α −1 N + α −1 N α N + α −1 N

= 1 {Z

2

≥1−Z

1

,Z

3

≥1−Z

2

,...} π 2

N−1

The total mass of the density is less than 1 since there is a positive probability that Z is not defined. On the event that Z is not defined, start over until the the process yields a sequence Z . Then almost surely, the procedure terminates and yields a random sequence Z with density

1 Q N

π 2

N −1

1 {Z

2

≥1−Z

1

,Z

3

≥1−Z

2

,...}

where Q N is the non-rejection probability

Q N = E[2/(α N + α −1 N )]

Finally, the sequence Y in the algorithm is given by Y = (Z 1 , 1 − Z 2 , Z 3 , 1 − Z 4 . . .) and the density of Y is

1 Q N

π 2

N−1

1 {Y

1

≥Y

2

≤Y

3

≥Y

4

...} (3) which is exactly what we were aiming at. Therefore, producing a random per- mutation from Y yields a random, uniform alternating permutation.

Let us prove the bound on the rejection probability. First, the invariant probability measure of the Markov chain X is

µ(dy) = 2 sin 2 ( π 2 y)dy Indeed,

Z 1

0

µ(dx)f x (y) = 2 Z 1

1−y

dx π 2 sin( π

2 x) sin( π

2 y) = 2 sin 2 ( π

2 y) = µ(dy)

(6)

The non-rejection probability can be expressed as Q N = E[2/(α N + α −1 N )] = 2E sin( π 2 X N ) sin( π 2 X 1 )

sin 2 ( π 2 X N ) + sin 2 ( π 2 X 1 ) ≥ E sin( π

2 X N ) sin( π 2 X 1 ) Write

E sin( π

2 X N ) sin( π

2 X 1 ) = Z 1

0

dx Z 1

0

P x (X N ∈ dy) sin( π

2 x) sin( π 2 y)

≥ Z 1

0

dx Z 1

0

P x (X N ∈ dy) sin 2 ( π

2 x) sin( π

2 x) sin( π 2 y)

= 1

2 Z 1

0

µ(dx) Z 1

0

P x (X N ∈ dy) sin( π

2 x) sin( π 2 y)

= 1

2 E µ sin( π

2 X 0 ) sin( π 2 X N )

where E µ stands for the expectation for the Markov chain started with initial distribution µ. Since µ is the invariant measure, under P µ , both X 1 and X N

are distributed according to µ. In particular, if δ ∈ [0, 1] is the real such that µ([0, δ]) = 1/3, then

P µ (X 1 ≥ δ, X N ≥ δ) ≥ 1 3

On the event {X 1 ≥ δ, X N ≥ δ}, we have sin( π 2 X 1 ) ≥ sin( π 2 δ) and sin( π 2 X N ) ≥ sin( π 2 δ). Hence

E µ sin( π

2 X 1 ) sin( π

2 X N ) ≥ 1 3 sin 2 ( π

2 δ)

Using the fact that, for x ∈ [0, 1], sin( π 2 x) ≥ x, we have δ ≥ δ , where δ is the real such that

2 Z δ

0

x 2 dx = 1 3

This gives δ ≥ 2 −1/3 and a fortiori δ ≥ 2/3, which leads to the bound 7/8 in the theorem.

Finally, notice that using randomized quicksort, we get the same complexity on average as if we were using quicksort with a random, uniform permutation (whereas we are dealing here with a random, uniform alternating permutation).

See [K].

3 Concluding remarks

Although this does not appear explicitely in the proof, the method used here is

based on the theory of quasistationary distributions for Markov chains. Indeed,

a random sequence on [0, 1] can be viewed as a Markov chain, and a random

alternating sequence is a submarkovian chain obtained from the initial Markov

chain by forbidding some transitions. Transforming this submarkovian chain

(7)

into a Markov chain leads to the definition of X. For an introduction to qua- sistationary distributions in the case when the state space is discrete, see for instance [S].

The sequence (X 1 , 1 − X 2 , X 3 , 1 − X 4 . . .) is, loosely speaking, a sequence conditioned to be alternating forever. If we want to obtain a finite-length alter- nating sequence, we get the bias α N . To eliminate this bias, we need to use a rejection procedure.

When N → ∞, the law of X N converges to the invariant measure and X N is asymptotically independent of X 1 . Therefore, the rejection probability converges to

1 − 4 Z 1

0

dx Z 1

0

dy sin( π 2 x) sin 3 ( π 2 y) sin 2 ( π 2 x) + sin 2 ( π 2 y)

Alternatively, comparing (1) with (3), we see that (2/π) N Q N = p N . Moreover, it is known that for large N,

p N ∼ 4 π

2 π

N +1

(see Example IV.35 in [FS]) whence Q N → 8/π 2 as N → ∞.

This method inpired by quasistationary distributions may be adapted to generate more general types of permutations.

Acknowledgments. Christian Houdr´e brought my attention to this topic.

I thank Cyril Banderier for interesting discussions.

References

[A] Andr´e, D. D´eveloppements de sec x et tan x. Comptes Rendus Acad. Sci., Paris 88, 965-967, 1879

[DFLS] Duchon, Philippe; Flajolet, Philippe; Louchard, Guy; Schaeffer, Gilles.

Boltzmann samplers for the random generation of combinatorial struc- tures. Combin. Probab. Comput.13 (2004), no. 4-5, 577-625.

[FS] Flajolet, Philippe; Sedgewick, Robert. Analytic combinatorics. Cambridge University Press, Cambridge, 2009.

[K] Knuth, Donald E. The art of computer programming. Volume 3. Sorting and searching. Addison-Wesley Series in Computer Science and Informa- tion Processing. Addison-Wesley Publishing Co., 1973.

[S] Seneta, E. Non-negative matrices and Markov chains. Revised reprint of

the second (1981) edition. Springer Series in Statistics. Springer, New

York, 2006.

(8)

[ST] Stanley, Richard P. A survey of alternating permutations. Combinatorics

and graphs, 165-196, Contemp. Math., 531, Amer. Math. Soc., Provi-

dence, RI, 2010.

Références

Documents relatifs

By using now this result, Lemma 15 and the Markov property of the random walk and of Brownian motion, we deduce the following:..

Entropy; Fisher information; Boltzmann; Shannon; Voiculescu; Markov processes; Diffu- sion processes; Central limit theorem; Free probability; Random matrices; Ginibre ensemble;

Keywords Regular class of permutations · Signature of a permutation · Uniform random sampling · Exponential generating function · Timed automata · Boltzmann

Starting from the work of Boltz- mann in the kinetic theory of gases, various universes are visited, in- cluding Markov processes and their Helmholtz free energy, the

On the other hand, from the math- ematical point of view, various parameters of random permutations have been studied in combinatorics and probability, like the distribution of

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

Récemment, Enriquez, Sabot et Zindy (cf. [17]) ont donné une nouvelle preuve de ce théorème dans le cas où 0 &lt; κ &lt; 1 par une tout autre méthode, basée sur l’étude fine

Even if the Boltzmann sampler ΓG(x, y) already yields a polynomial-time uniform ran- dom sampler for planar graphs, the expected time complexity to generate a graph of size n