we have an array A that : in array A exist a pair (i, j) that i<j and A[i]>A[j]. why do we have at least j-i inversions in array A?
Asked
Active
Viewed 47 times
-1
-
Welcome to the StackOverflow community! Your question is not really understandable, please try to be more specific. You might want edit your post. – mrpasqal Nov 11 '20 at 21:54
1 Answers
0
(i, j)
is one inversion. The other j-i-1
involve the indices k
such that i<k<j
, since either A[i]>A[k]
or A[k]>A[j]
(otherwise, A[i]<=A[k]<=A[k]
, which implies A[i]<=A[j]
and contradicts the assumption that A[i]>A[j]
).

David Eisenstat
- 64,237
- 7
- 60
- 120