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.

Showing 1-4 of 4 results.

A159323 Triangle read by rows: T(n,k) = A129178(n,k) * (n*(n-1)/2 - k).

Original entry on oeis.org

0, 0, 2, 12, 4, 48, 40, 24, 6, 160, 216, 224, 182, 96, 40, 8, 480, 896, 1248, 1440, 1386, 1100, 738, 416, 182, 60, 10, 1344, 3200, 5472, 7776, 9588, 10528, 10200, 8932, 7046, 4992, 3124, 1720, 810, 304, 84, 12
Offset: 0

Views

Author

Harmen Wassenaar (towr(AT)ai.rug.nl), Apr 10 2009

Keywords

Comments

Summing the rows and dividing by n! gives the average number of comparisons required by a insertion sort on n (distinct) elements. Each entry in the triangle gives the separate contribution of permutations that require (n(n-1)/2 - k) comparisons (i.e. we start with the one taking most comparisons and work down to the one taking least).

Examples

			For n=3, permutations 123, 132, 213 and 312 require three comparisons to sort, and permutations 231 and 321 require two. So a(3,0) = 4*3 = 12, and a(3,1) = 2*2 = 4.
Triangle T(n,k) begins:
    0;
    0;
    2;
   12,   4;
   48,  40,   24,    6;
  160, 216,  224,  182,   96,   40,   8;
  480, 896, 1248, 1440, 1386, 1100, 738, 416, 182, 60, 10;
  ...
		

Programs

  • Maple
    s:= proc(n) option remember; `if`(n<0, 1, `if`(n=0, 2, t^n+s(n-1))) end:
    p:= proc(n) option remember; `if`(n<0, 1, expand(s(n-2)*p(n-1))) end:
    T:= n-> (h-> seq(coeff(h,t,i)*(n*(n-1)/2-i), i=0..degree(h)))(p(n)):
    seq(T(n), n=0..8);  # Alois P. Heinz, Dec 16 2016
  • Mathematica
    s[n_] := s[n] = If[n < 0, 1, If[n == 0, 2, t^n + s[n - 1]]];
    p[n_] := p[n] = If[n < 0, 1, Expand[s[n - 2]*p[n - 1]]];
    T[n_] := Function[h, Table[Coefficient[h, t, i]*(n*(n - 1)/2 - i), {i, 0, Exponent[h, t]}]][p[n]];
    Table[T[n], {n, 0, 8}] // Flatten (* Jean-François Alcover, Apr 06 2017, after Alois P. Heinz *)

Formula

a(n,k) = A129178(n,k) * (n(n-1)/2 - k).

Extensions

One term for row n=0 prepended by Alois P. Heinz, Dec 16 2016

A159324 n! times the average number of comparisons required by an insertion sort of n (distinct) elements.

Original entry on oeis.org

0, 0, 2, 16, 118, 926, 7956, 75132, 777456, 8771184, 107307360, 1416252960, 20068629120, 304002322560, 4903642679040, 83928856838400, 1519397749094400, 29010025797580800, 582647327132774400, 12280347845905305600, 271030782903552000000, 6251213902855219200000
Offset: 0

Views

Author

Harmen Wassenaar (towr(AT)ai.rug.nl), Apr 10 2009

Keywords

Examples

			For n=3, insertion sorting 123, 213, 213, 231, 312, 321 takes 3+3+3+2+3+2 = 4*3+2*2 = 16 comparisons.
		

Crossrefs

Row sums of triangle A159323.

Programs

  • Maple
    a:= proc(n) option remember;
          `if`(n<2, 0, a(n-1)*n + (n-1)! * (n-1)*(n+2)/2)
        end:
    seq(a(n), n=0..30); # Alois P. Heinz, May 14 2012
    # second Maple program:
    a:= proc(n) option remember; `if`(n<3, [0$2, 2][n+1],
          ((2*n^3-n^2-5*n+2)*a(n-1)-(n+2)*(n-1)^3*a(n-2))/((n-2)*(n+1)))
        end:
    seq(a(n), n=0..30); # Alois P. Heinz, Dec 16 2016
  • Mathematica
    a[n_] := n! ((n+1)(n+2)/4 - HarmonicNumber[n] - 1/2); Table[a[n], {n, 0, 30}] (* Jean-François Alcover, Apr 12 2017, after Gary Detlefs *)

Formula

a(n) = a(n-1)*(n) + n! *(n+1)/2 - (n-1)!.
a(n) = Sum_k A159323(n,k) = Sum_k A129178(n,k) * (n(n-1)/2 - k).
a(n) = n!/4 *(n^2+3*n-4*H(n)), where H(n) = Sum_{k=1..n} 1/k. - Gary Detlefs, Sep 02 2010
a(n) = A138772(n+1) - A000254(n). - Gary Detlefs, May 13 2012
a(n) = ((2*n^3-n^2-5*n+2)*a(n-1)-(n+2)*(n-1)^3*a(n-2))/((n-2)*(n+1)) for n>2. - Alois P. Heinz, Dec 16 2016
a(n) = 2 * A285231(n+1). - Alois P. Heinz, Apr 15 2017

A126673 Third diagonal of A126671.

Original entry on oeis.org

0, 2, 26, 274, 2844, 30708, 351504, 4292496, 55988640, 779171040, 11545476480, 181705299840, 3029581820160, 53376951801600, 991337037465600, 19363464423475200, 396915849843609600, 8520964324004966400, 191220598650009600000, 4477883953203763200000, 109242544826541772800000
Offset: 2

Views

Author

N. J. A. Sloane and Carlo Wood (carlo(AT)alinoe.com), Feb 13 2007

Keywords

Comments

It appears that a(n) = sum of invc(p) over all permutations p of {1,2,...,n}, where invc(p) is defined (by Carlitz) in the following way: express p in standard cycle form (i.e., cycles ordered by increasing smallest elements with each cycle written with its smallest element in the first position), then remove the parentheses and count the inversions in the obtained word. a(3)=2 because the six permutations 123,132,312,213,231 and 321 of {1,2,3} yield the words 123,123,132,123,123 and 132, respectively, having a total of 0+0+1+0+0+1 = 2 inversions. a(n) = Sum_{k>=0} k*A129178(n,k). - Emeric Deutsch, Oct 10 2007

References

  • L. Carlitz, Generalized Stirling numbers, Combinatorial Analysis Notes, Duke University, 1968, 1-7.

Crossrefs

Programs

  • Magma
    [Factorial(n)*(n*(n-5)/4 + HarmonicNumber(n)): n in [2..25]]; // G. C. Greubel, May 05 2019
    
  • Maple
    seq(n!*(sum(1/k, k = 1 .. n)+(1/4)*n*(n-5)), n = 2 .. 21); # Emeric Deutsch, Oct 10 2007
  • Mathematica
    Table[n!*(n*(n-5)/4 + HarmonicNumber[n]), {n,2,25}] (* G. C. Greubel, May 05 2019 *)
  • PARI
    my(x='x+O('x^30)); concat([0], Vec(serlaplace( (2*x - 3*x^2 + 2*(1-x)^2*log(1-x))/(2*(-1+x)^3) ))) \\ G. C. Greubel, May 05 2019
    
  • Sage
    [factorial(n)*(n*(n-5)/4 + harmonic_number(n)) for n in (2..25)] # G. C. Greubel, May 05 2019

Formula

a(n) = n! * (n*(n-5)/4 + 1 + 1/2 + ... + 1/n). - Emeric Deutsch, Oct 10 2007
E.g.f.: (2*x - 3*x^2 + 2*(1-x)^2 * log(1-x)) / (2*(-1+x)^3). - G. C. Greubel, May 05 2019
a(n) = 2 * Sum_{k>=1} k * A381529(n,k). - Alois P. Heinz, Feb 26 2025

A159325 Median number of comparisons used by insertion sort on n (distinct) elements.

Original entry on oeis.org

0, 1, 3, 5, 8, 11, 15, 19, 24, 30, 36, 42, 49, 56, 64, 73, 82, 91, 101, 111, 122, 134, 146, 158, 171, 185
Offset: 1

Views

Author

Harmen Wassenaar (towr(AT)ai.rug.nl), Apr 10 2009

Keywords

Comments

The frequencies of the number of comparisons are given by sequence A129178, so if Sum_{k=0..i-1} A129178(n,k) < n!/2 and Sum_{k=0..i} A129178(n,k) > n!/2, then the median is entry i, which corresponds to n(n-1)/2-i comparisons.
Close to average number of comparisons: A159324(n)/n!

Examples

			For n=3, permutations 123,132,213,231,312,321 require 3,3,3,2,3,2 comparisons respectively, so the median is 3.
		

Crossrefs

Showing 1-4 of 4 results.