• edited by
40,942 views
97 97 votes

In a permutation \(a_1 ... a_n\), of n distinct integers, an inversion is a pair \((a_i, a_j)\) such that \(i < j\) and \(a_i > a_j\).

If all permutations are equally likely, what is the expected number of inversions in a randomly chosen permutation of \(1. . . n\)?

  1. \(\dfrac{n(n-1)}{2}\)
  2. \(\dfrac{n(n-1)}{4}\)
  3. \(\dfrac{n(n+1)}{4}\)
  4. \(2n[\log_2n]\)

15 Answers

3 3 votes

61.Take n=3,

Permutation ----> no of inversions

1 2 3                        0

1 3 2                        1

2 3 1                         2

2 1 3                         1

3 1 2                         2

3 2 1                         3

Total inversions =9, no of permutation =6,

So, here n=6

putting it in option n(n-1)/4=6⨉5/4=7.5

So, (B) is most closer option

62. Now elements are comes like 5,4,3,2,1

So,  first 5 comes order is 5--------------0 inversion

 Now, 4 comes........"       " 5,4 -----------1 inversion

 Now 3 comes..........."       " 4,5,3--------2 inversions

Now 2      "..........................3,4,5,2--------3  inversions

Now 1     " .......................2,3,4,5,1---------4 inversions

total 10 inversion

No more permutation could be done in insertion sort

So, number of permutation could be n(n-1)/2= O(n2)

Ans (A) here

0 0 votes
Select 2 out of n and half of them will be inversions B.
0 0 votes

Ans -B 

Let \(X_{ij}\) be an indicator random variable s.t. $$X_{ij} = \begin{cases} 0 &\mbox{if } (a_i,a_j) \text {not inverted} \\ 1 & \mbox{if } otherwise. \end{cases}$$ Let random variable \(X\) denotes total number of inversions. So clearly \(X=\sum\limits_{\substack{i,j \\ i<j}}X_{ij}\). Note that their are \(^n\mathrm{C}_2\) terms in summation, because there are total \(^n\mathrm{C}_2\) pairs, and each pair is either inverted or not.
So now we want to find \(E(X)\). Now \(E(X)=\sum\limits_{\substack{i,j \\ i<j}}E(X_{ij})\). But \(E(X_{ij}) = \frac{1}{2}\), because for any pair, probability of inversion is same as of not inversion.
So \(E(X) = \frac{^n\mathrm{C}_2}{2} = \frac{n(n-1)}{4}\).
So option (B) is correct.

0 0 votes

https://youtu.be/KFcodn4qfrQ

please check this video for the method used by others to solve the question (linearity of expectation) MIT video

just think it as expected no. of heads in n coin flips.

here n coin flips refers to no. of pairs in the sequence which is n©2. probability of head = probability of a pair being a inversion=0.5

 

remember expectation of a binomial distribution is np, here also same.

expectation of no. of inversion pairs =np=n©2*0.5

 

Answer:
Position:
Show:

Related questions

61 61 votes
5 answers 5 answers
14.7k
14.7k views
Kathleen asked Sep 17, 2014
14,723 views
A program consists of two modules executed sequentially. Let $f_1(t)$ and $f_2(t)$ respectively denote the probability density functions of time taken to execute the two ...
8 8 votes
6 6 answers
3.9k
3.9k views
Arjun asked Feb 27, 2025
3,926 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...
94 94 votes
11 answers 11 answers
31.5k
31.5k views
go_editor asked Apr 24, 2016
31,530 views
In a permutation $a_1\ldots a_n$, of $n$ distinct integers, an inversion is a pair $(a_i, a_j)$ such that $i < j$ and $a_i a_j.$What would be the worst case time complex...
85 85 votes
3 answers 3 answers
26.9k
26.9k views
Kathleen asked Sep 16, 2014
26,907 views
The usual $\Theta(n^2)$ implementation of Insertion Sort to sort an array uses linear search to identify the position where an element is to be inserted into the already ...