323 views

1 Answer

0 votes
0 votes

$i<j ; A[i] > A[j]$

If an array is already sorted then number of inversions would be ZERO.

Now if the array is  REVERSE SORTED/ORDER then only it will have maximum number of inversions

<n,n-1,n-2,........2,1> it'll have n+n-1+n-2+...+1 = n(n-1)/2 inversions.

For example:

$\left \langle 8,6,3,2,1 \right \rangle$ now #inversions for this case are 10as following:

$(8,6) (8,3) (8,2) (8,1) (6,3) (6,2) (6,1) (3,2) (3,1) (2,1)$

Related questions

0 votes
0 votes
0 answers
1
akash.dinkar12 asked Jun 26, 2019
217 views
Give an algorithm that determines the number of inversions in any permutation on $n$ elements in $\Theta (n\ lg\ n)$ worst-case time. (Hint: Modify merge sort.)
0 votes
0 votes
0 answers
2
akash.dinkar12 asked Jun 26, 2019
159 views
What is the relationship between the running time of insertion sort and the number of inversions in the input array? Justify your answer.
0 votes
0 votes
1 answer
3
akash.dinkar12 asked Jun 26, 2019
243 views
List the five inversions of the array $\langle 2,3,8,6,1\rangle$
1 votes
1 votes
1 answer
4
akash.dinkar12 asked Jun 28, 2019
680 views
Explain why the worst-case running time for bucket sort is $\Theta(n^2)$. What simple change to the algorithm preserves its linear average-case running time and makes its...