The OEIS mourns the passing of Jim Simons and is grateful to the Simons Foundation for its support of research in many branches of science, including the OEIS.
login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A115107 Numerator of q_n = -4*n + 2*(1+n)*HarmonicNumber(n). 15

%I #57 Feb 05 2024 01:58:35

%S 0,0,1,8,29,37,103,472,2369,2593,30791,32891,452993,476753,499061,

%T 2080328,18358463,18999103,124184839,127860511,26274175,8982005,

%U 211524139,648798629,16562041459,16891532467,154883957203,157646059403,4649180818987,4724140023307

%N Numerator of q_n = -4*n + 2*(1+n)*HarmonicNumber(n).

%C Average time to quicksort n items in random order.

%C From _Petros Hadjicostas_, Oct 26 2019: (Start)

%C 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. See, for example, A093418 and A288964. Other variations of the above formula are possible.

%C Let X_n be the random number of comparisons needed to sort a list of numbers in the symmetric group S_n and let R_n be the rank of the pivot. According to Havil (2003, pp. 128-130), we have X_n = n + X_{R_n-1} + X_{n-R_n} because it takes 1 unit of comparison time to pick the pivot and n-1 comparisons to divide the data into two lists of numbers (less than the pivot and greater than the pivot). No matter how we pick the pivot, we have to assume X_n and R_n are independent random variables. We let X_0 = 0.

%C Denoting expectation by E(.) and conditional expectation by E(.|.), we have E(X_n) = Sum_{r = 1..n} E(n + X_{R_n-1} + X_{n-R_n} | R_n=r) * P(R_n=r) = n + (1/n) * (E(X_{r-1}) + E(X_{n-r})) The last step follows from the assumed independence of X_n and R_n. This simplifies to E(X_n) = n + (2/n) * Sum_{r = 0..n-1} E(X_r). As in Havil (2003), solving the recurrence we get E(X_n) = -3*n + 2*(1+n)*HarmonicNumber(n). Here A093418(n) = numerator(E(X_n)) and A096620(n) = denominator(E(X_n)).

%C Note that E(X_n)*n! = (-3*n + 2*(1+n)*HarmonicNumber(n)) * n! = A063090(n), and according to the documentation of that sequence, A063090(n)/(n*n!) is the "average number of comparisons needed to find a node in a binary search tree containing n nodes inserted in a random order". See Knuth (1998, Vol. 3, pp. 430-431 and Exercise 6 on pp. 454-455).

%C Other authors (e.g., Cameron (1996)) do not count the choice of the pivot as a comparison time. In such a case, if we let Y_n be the modified number of comparisons used by quicksort to sort a random list of length n, we get the modified recurrence Y_n = n - 1 + Y_{R_n-1} + Y_{n-R_n}, from which we get E(Y_n) = n - 1 + (2/n) * Sum_{r = 0..n-1} E(Y_r). Solving this modified recurrence, we get E(Y_n) = fr_2(n) = -4*n + + 2*(1+n)*HarmonicNumber(n). In such a case, a(n) = numerator(E(Y_n)) = numerator(fr(n)) and A288964(n) = n! * E(Y_n) = n! * fr(n). In addition, A096620(n) = denominator(E(Y_n)) = denominator(fr(n)).

%C (end)

%D Peter J. Cameron, Combinatorics: Topics, Techniques and Algorithms, Cambridge Univ. Press, 1996; see pp. 66-68.

%D J. H. Conway and R. K. Guy, The Book of Numbers. New York: Springer-Verlag, 1996, pp. 143 and 258-259.

%D Julian Havil, Gamma: Exploring Euler's constant, Princeton University Press, 2003; see pp. 128-130.

%D D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 3, 1998; see pp. 427-431 and 454-455.

%H G. C. Greubel, <a href="/A115107/b115107.txt">Table of n, a(n) for n = 0..1000</a> [a(0) = 0 by _Georg Fischer_, Oct 28 2019]

%H M. Kauers and P. Paule, <a href="https://doi.org/10.1007/978-3-7091-0445-3">The Concrete Tetrahedron</a>, Springer, 2011; see p. 4. [They agree with Cameron's recurrence that yields numerators in this sequence and denominators in A096620.]

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/Quicksort.html">Quicksort</a>. [He uses Havil's recurrence which yields numerators in A093418 and denominators in A096620.]

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/HarmonicNumber.html">Harmonic Number</a>.

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Quicksort">Quicksort</a>. [The article uses Cameron's recurrence which yields numerators in this sequence and denominators in A096620.]

%e q_n = fr(n) = 0, 0, 1, 8/3, 29/6, 37/5, 103/10, 472/35, 2369/140, 2593/126, ... = a(n)/A096620(n) = A288964(n)/n!.

%e From _Petros Hadjicostas_, Oct 26 2019: (Start)

%e Using the notation in the comments, Y_3 = 3-1 + Y_{R_3-1} + Y_{3-R_3} = 2 + Y_{R_3-1} + Y_{3-R_3}, where the (random) pivot R_3 has a uniform distribution on the set {1,2,3} (and it is independent of Y_1, Y_2, Y_3).

%e Since P(R_3 = r) = 1/3 for r = 1,2,3, we have that Y_3 = 2 + Y_0 + Y_2 = 2 + 0 + 1 = 3 w.p. 1/3; Y_3 = 2 + Y_1 + Y_1 = 2 w.p. 1/3; and Y_3 = 2 + Y_2 + Y_0 = 2 + 1 + 0 = 3 w.p. 1/3. Thus, fr(3) = E(Y_n) = 3*(1/3) + 2*(1/3) + 3*(1/3) = 8/3, and a(3) = numerator(8/3) = 8 while A096620(3) = 3. (End)

%t a[n_] := Numerator[ -4n + 2(n + 1)HarmonicNumber[n]]; Array[a, 29] (* _Robert G. Wilson v_, May 01 2006 *)

%o (PARI) {h(n) = sum(k=1,n,1/k)};

%o for(n=1,30, print1(numerator(-4*n + 2*(n+1)*h(n)), ", ")) \\ _G. C. Greubel_, Sep 01 2018

%o (Magma) [Numerator(-4*n + 2*(n+1)*HarmonicNumber(n)): n in [1..30]]; // _G. C. Greubel_, Sep 01 2018

%o (Python)

%o from sympy import harmonic

%o def A115107(n): return ((n+1<<1)*harmonic(n)-(n<<2)).p # _Chai Wah Wu_, Feb 04 2024

%Y Cf. A063090, A093418, A096620 (denominators), A288964.

%K nonn,frac

%O 0,4

%A _N. J. A. Sloane_, Mar 07 2006

%E a(0) = 0 prepended by _Petros Hadjicostas_, Oct 26 2019

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified June 4 08:21 EDT 2024. Contains 373092 sequences. (Running on oeis4.)