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.

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

A279683 Number of move operations required to sort all permutations of [n] by MTF sort.

Original entry on oeis.org

0, 0, 1, 9, 78, 750, 8220, 102900, 1463280, 23451120, 419942880, 8331634080, 181689298560, 4323472433280, 111534141438720, 3101254066310400, 92468631077222400, 2943141763622860800, 99596858633182310400, 3570677764371119001600, 135190500045467682816000
Offset: 0

Views

Author

Alois P. Heinz, Dec 16 2016

Keywords

Comments

MTF sort is an (inefficient) sorting algorithm: the first element that is smaller than its predecessor is moved to front repeatedly until the sequence is sorted.
Conjecture: primes p such that p^4 divides a(p) are the Wolstenholme primes A088164. - Amiram Eldar and Thomas Ordowski, Jan 15 2020

Examples

			a(0) = a(1) = 0 because 0 or 1 elements are already sorted.
a(2) = 1: [1,2] is sorted and [2,1] needs one move.
a(3) = 9: [1,2,3](0), [1,3,2]->[2,1,3]->[1,2,3](2), [2,1,3]->[1,2,3](1), [2,3,1]->[1,2,3](1), [3,1,2]->[1,3,2]->[2,1,3]->[1,2,3](3), [3,2,1]->[2,3,1]->[1,2,3](2); sum of all moves gives 0+2+1+1+3+2 = 9.
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember;
          `if`(n=0, 0, a(n-1)*n + (n-1)! * (2^(n-1)-1))
        end:
    seq(a(n), n=0..20);
    # second Maple program:
    a:= proc(n) option remember; `if`(n<3, [0$2, 1][n+1],
          (4*n-3)*a(n-1)-(n-1)*(5*n-7)*a(n-2)+(2*n-2)*(n-2)^2*a(n-3))
        end:
    seq(a(n), n=0..20);
  • Mathematica
    a[0] = 0; a[n_] := a[n] = a[n-1]*n + (n-1)!*(2^(n-1) - 1);
    Table[a[n], {n, 0, 20}] (* Jean-François Alcover, May 30 2018 *)

Formula

a(n) = a(n-1)*n + (n-1)! * (2^(n-1)-1) for n>0, a(0) = 0.
a(n) = (4*n-3)*a(n-1)-(n-1)*(5*n-7)*a(n-2)+(2*n-2)*(n-2)^2*a(n-3) for n>2.
a(n) ~ 2^n * (n-1)!. - Vaclav Kotesovec, Dec 25 2016
a(n) = n! * Sum_{k=1..n} (2^(k-1)-1)/k = A000142(n)*A330718(n)/A330719(n), for n > 0. - Amiram Eldar and Thomas Ordowski, Jan 15 2020

A212396 Numerator of the average number of move operations required by an insertion sort of n (distinct) elements.

Original entry on oeis.org

0, 0, 3, 23, 41, 313, 73, 676, 3439, 38231, 46169, 602359, 703999, 10565707, 12071497, 13669093, 30716561, 582722017, 215455199, 4516351061, 991731385, 361369795, 393466951, 9817955321, 31848396101, 858318957533, 922672670033, 8903430207697, 9522990978097
Offset: 0

Views

Author

Alois P. Heinz, May 14 2012

Keywords

Comments

The average number of move operations is 1/n! times the number of move operations required to sort all permutations of [n] (A212395), assuming that each permutation is equiprobable.

Examples

			0/1, 0/1, 3/2, 23/6, 41/6, 313/30, 73/5, 676/35, 3439/140, 38231/1260, 46169/1260, 602359/13860, 703999/13860 ... = A212396/A212397
		

Crossrefs

Denominators are in A212397.

Programs

  • Maple
    b:= proc(n) option remember;
          `if`(n=0, 0, b(n-1)*n + (n-1)! * (n-1)*(n+4)/2)
        end:
    a:= n-> numer(b(n)/n!):
    seq(a(n), n=0..30);
    # second Maple program:
    a:= n-> numer(expand(n*(n+7)/4 -2*(Psi(n+1)+gamma))):
    seq(a(n), n=0..30);
  • Mathematica
    a[n_] := Numerator[n (n + 7)/4 - 2 HarmonicNumber[n]];
    Table[a[n], {n, 0, 30}] (* Jean-François Alcover, May 29 2018, from 2nd formula *)

Formula

a(n) = numerator of A212395(n)/A000142(n).
a(n) = numerator of n*(n+7)/4 - 2*H(n) with n-th harmonic number H(n) = Sum_{k=1..n} 1/k = A001008(n)/A002805(n).
a(n) = numerator of n*(n+7)/4 - 2*(Psi(n+1)+gamma) with digamma function Psi and the Euler-Mascheroni constant gamma = A001620.

A212397 Denominator of the average number of move operations required by an insertion sort of n (distinct) elements.

Original entry on oeis.org

1, 1, 2, 6, 6, 30, 5, 35, 140, 1260, 1260, 13860, 13860, 180180, 180180, 180180, 360360, 6126120, 2042040, 38798760, 7759752, 2586584, 2586584, 59491432, 178474296, 4461857400, 4461857400, 40156716600, 40156716600, 1164544781400, 1164544781400
Offset: 0

Views

Author

Alois P. Heinz, May 14 2012

Keywords

Comments

The average number of move operations is 1/n! times the number of move operations required to sort all permutations of [n] (A212395), assuming that each permutation is equiprobable.

Crossrefs

Numerators are in A212396.

Programs

  • Maple
    b:= proc(n) option remember;
          `if`(n=0, 0, b(n-1)*n + (n-1)! * (n-1)*(n+4)/2)
        end:
    a:= n-> denom(b(n)/n!):
    seq(a(n), n=0..30);
  • Mathematica
    a[n_] := Denominator[n (n + 7)/4 - 2 HarmonicNumber[n]];
    Table[a[n], {n, 0, 30}] (* Jean-François Alcover, May 29 2018, from 2nd formula in A212396 *)

Formula

a(n) = denominator of A212395(n)/A000142(n).
Showing 1-4 of 4 results.