cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A288964 Number of key comparisons to sort all n! permutations of n elements by quicksort.

This page as a plain text file.
%I A288964 #67 Jun 27 2023 12:01:42
%S A288964 0,0,2,16,116,888,7416,67968,682272,7467840,88678080,1136712960,
%T A288964 15655438080,230672171520,3621985113600,60392753971200,
%U A288964 1065907048550400,19855856150323200,389354639411404800,8017578241634304000,172991656889856000000,3903132531903897600000
%N A288964 Number of key comparisons to sort all n! permutations of n elements by quicksort.
%C A288964 From _Petros Hadjicostas_, May 04 2020: (Start)
%C A288964 Depending on the assumptions used in the literature, the average number to sort n items in random order by quicksort appears as -C*n + 2*(1+n)*HarmonicNumber(n), where C = 2, 3, or 4. (To get the number of key comparisons to sort all n! permutations of n elements by quicksort, multiply this number by n!.)
%C A288964 For this sequence, we have C = 4. The corresponding number of key comparisons to sort all n! permutations of n elements by quicksort when C = 3 is A063090(n). Thus, a(n) = A063090(n) - n!*n.
%C A288964 For more details, see my comments and references for sequences A093418, A096620, and A115107. (End)
%H A288964 Daniel Krenn, <a href="/A288964/b288964.txt">Table of n, a(n) for n = 0..100</a>
%H A288964 Pamela E. Harris, Jan Kretschmann, and J. Carlos Martínez Mori, <a href="https://arxiv.org/abs/2306.13065">Lucky Cars and the Quicksort Algorithm</a>, arXiv:2306.13065 [math.CO], 2023.
%H A288964 <a href="/index/So#sorting">Index entries for sequences related to sorting</a>
%F A288964 a(n) = n!*(2*(n+1)*H(n) - 4*n).
%F A288964 c(n) = a(n) / n! satisfies c(n) = (n-1) + 2/n * Sum_{i < n} c(i).
%F A288964 a(n) = 2*A002538(n-1), n >= 2. - _Omar E. Pol_, Jun 20 2017
%F A288964 E.g.f.: -2*log(1-x)/(1-x)^2 - 2*x/(1-x)^2. - _Daniel Krenn_, Jun 20 2017
%F A288964 a(n) = ((2*n^2-3*n-1)*a(n-1) -(n-1)^2*n*a(n-2))/(n-2) for n >= 3, a(n) = n*(n-1) for n < 3. - _Alois P. Heinz_, Jun 21 2017
%F A288964 From _Petros Hadjicostas_, May 03 2020: (Start)
%F A288964 a(n) = A063090(n) - n!*n for n >= 1.
%F A288964 a(n) = n!*A115107(n)/A096620(n) = n!*(-n + A093418(n)/A096620(n)). (End)
%p A288964 a:= proc(n) option remember; `if`(n<3, n*(n-1),
%p A288964       ((2*n^2-3*n-1)*a(n-1)-(n-1)^2*n*a(n-2))/(n-2))
%p A288964     end:
%p A288964 seq(a(n), n=0..25);  # _Alois P. Heinz_, Jun 21 2017
%t A288964 a[n_] := n! (2(n+1)HarmonicNumber[n] - 4n);
%t A288964 a /@ Range[0, 25] (* _Jean-François Alcover_, Oct 29 2020 *)
%o A288964 (SageMath) [n.factorial() * (2*(n+1)*sum(1/k for k in srange(1, n+1)) - 4*n) for n in srange(21)]
%o A288964 (SageMath) # alternative using the recurrence relation
%o A288964 @cached_function
%o A288964 def c(n):
%o A288964     if n <= 1:
%o A288964         return 0
%o A288964     return (n - 1) + 2/n*sum(c(i) for i in srange(n))
%o A288964 [n.factorial() * c(n) for n in srange(21)]
%Y A288964 Cf. A063090, A093418, A096620, A115107, A117627, A117628, A159324, A288965.
%K A288964 nonn
%O A288964 0,3
%A A288964 _Daniel Krenn_, Jun 20 2017