Logo

Greetings from The On-Line Encyclopedia of Integer Sequences!

Hints

Search: id:A161169
Displaying 1-1 of 1 results found. page 1
     Format: long | short | internal | text      Sort: relevance | references | number      Highlight: on | off
A161169 T(n,k) = number of permutations of {1..n} with at most k inversions. +0
1
1, 1, 1, 2, 1, 3, 5, 6, 1, 4, 9, 15, 20, 23, 24, 1, 5, 14, 29, 49, 71, 91, 106, 115, 119, 120, 1, 6, 20, 49, 98, 169, 259, 360, 461, 551, 622, 671, 700, 714, 719, 720, 1, 7, 27, 76, 174, 343, 602, 961, 1416, 1947, 2520, 3093, 3624, 4079, 4438, 4697, 4866, 4964, 5013 (list; table; graph; listen)
OFFSET

0,4

COMMENT

T(n,k) is also the number of permutations with Kendall tau distance ("bubble-sort distance") to the identity permutation being at most k. This is the number of swaps performed by the bubble-sort algorithm to sort the sequence.

The above only gives T(n,k) for k<=n(n-1)/2, but T(n,k)=n! for all k>=n(n-1)/2.

FORMULA

T(n,k) = sum_{i s.t. n-i<=k} T(n-1, k-(n-i))

= sum_{i=max(1,n-k) to n} T(n-1, k-n+i)

= sum_{j=max(k-n+1,0) to n} T(n-1, j)

T(n,k) = T(n,k-1) + T(n-1,k) - T(n-1,k-n), taking T(n,k)=0 for k<0.

Also, T(n,k) = n! - T(n, n(n-1)/2-k-1)

For k<=n, T(n,k) = A008302(n+1,k).

EXAMPLE

T(3,2)=5 because there are 5 permutations of {1,2,3} with at most 2 inversions: (1,2,3) with 0 inversions, (1,3,2), (2,1,3) with 1 inversion each, (2,3,1), (3,1,2) with 2 inversions each.

T(n,0)=1 because there is exactly 1 permutation (the identity permutation) with no inversions,

T(n,k) = n! for all k >= n(n-1)/2 because all permutations have at most n(n-1)/2 inversions.

PROGRAM

(Python) ct = {(0, 0): 1}

def c(n, k):

....if k<0: return 0

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

....if (n, k) in ct: return ct[(n, k)]

....ct[(n, k)] = c(n, k-1) + c(n-1, k) - c(n-1, k-n)

....return ct[(n, k)]

CROSSREFS

Partial sums of A008302.

Sequence in context: A063705 A137655 A167595 this_sequence A058202 A127201 A006769

Adjacent sequences: A161166 A161167 A161168 this_sequence A161170 A161171 A161172

KEYWORD

easy,nonn,tabl

AUTHOR

R. Shreevatsa (shreevatsa.public(AT)gmail.com), Jun 04 2009

page 1

Search completed in 0.002 seconds

Lookup | Welcome | Find friends | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Transforms | Puzzles | Hot | Classics
More pages | Superseeker | Maintained by N. J. A. Sloane (njas@research.att.com)

Last modified December 10 12:37 EST 2009. Contains 170569 sequences.


AT&T Labs Research