Number of n-element permutations with exactly k inversions
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In combinatorics, understanding the permutations of a set and their properties can reveal deep insights into mathematical theory and application. One such property of permutations is the number of inversions they contain. This article will delve into the concept of permutations with a specific focus on counting the number of n-element permutations with exactly k inversions.
Permutations and Inversions
Basics of Permutations
A permutation is a specific arrangement of a set of elements. For example, given a set {1, 2, 3}, the permutations are (1, 2, 3), (1, 3, 2), (2, 1, 3), and so on.
Understanding Inversions
An inversion in a permutation is a pair of elements that are out of their natural order. More formally, given a permutation of the set , an inversion is a pair (i, j) such that and .
For example, consider the permutation (3, 1, 2): • The pair (3, 1) is an inversion, as 3 > 1 and 3 precedes 1. • The pair (3, 2) is an inversion, as 3 > 2 and 3 precedes 2. • The pair (1, 2) is not an inversion since 1 < 2 and 1 precedes 2.
Thus, this permutation has exactly 2 inversions.
Counting Permutations with k Inversions
To find the number of permutations of n elements with exactly k inversions, we utilize the concept of Eulerian numbers and develop these concepts further.
Eulerian Numbers
Eulerian numbers count the number of permutations of the numbers from 1 to n that have exactly k ascents. This can be related to the number of permutations with inversions through combinatorial identities and recursive calculations.
Recursive Formula
The number of permutations of n elements with exactly k inversions can be determined using the following recursive relation:
Here, denotes the number of permutations of n elements with exactly k inversions.
Example Calculation
Consider calculating the number of permutations of 3 elements with exactly 2 inversions: Using the recursive formula, we express as:
•
Calculating separately: • (e.g., permutation (1, 2)) • (e.g., permutation (2, 1)) • (no permutation of two elements can have two inversions)
Thus, . Therefore, there are two permutations of three elements that have exactly two inversions: (3, 1, 2) and (2, 3, 1).
Summary Table
Here’s a concise table displaying the number of permutations with exactly k inversions for small n:
| n \ k | 0 | 1 | 2 | 3 | 4 | 5 |
| 1 | 1 | |||||
| 2 | 1 | 1 | ||||
| 3 | 1 | 2 | 2 | |||
| 4 | 1 | 3 | 5 | 6 | 5 | |
| 5 | 1 | 4 | 9 | 15 | 20 | 20 |
This table reflects only a few initial values and serves as a foundational reference for understanding permutations with k inversions.
Applications and Further Study
Studying permutations with a specific number of inversions has implications beyond pure mathematics; it intersects with computer science in areas such as sorting algorithms and network theory, where inversions reflect disorder or deviation from optimal states.
Further Study: • Generating Functions: Explore how generating functions can provide a compact form for representing and calculating permutations with inversions. • Connections with Sorting Algorithms: Investigate the correlation between inversion count and sorting algorithm complexity.
In conclusion, understanding permutations with a certain number of inversions provides rich mathematical exercises and has practical applications across computational fields. Whether through recursive formulations or deeper combinatorial identities, this topic offers many pathways for exploration and discovery.
Related reading
- Number of sub-sequences in a given sequence
- Number of subarrays divisible by k
- Number of substrings in range l, r that can be permuted to palindrome
- Number of ways of correctly arranging parenthesis
- Number of ways to divide n objects in k groups, such that no group will have fewer objects than previously formed groups?
- Number of ways to make change for amount N
- Number of Zeros in the binary representation of an Integer
- Occlusion algorithms collection

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.