views:

51

answers:

3

Hi I have read something in the site that inversion means if i<j then A[i]>A[j] and it has some exercises about this , I have a lot of questions but I want to ask just one of them at first and then i will do the other exercises by myself if I can!!

Exercise: What permutation array (1,2, ..., n) has the highest number of inversion? What are these? thanks

+1  A: 

Well, the identity permutation (1,2,...,n) has no inversions. Since an inversion is a pair of elements that are in reverse order than their indices, the answer probably involves some reversal of that permutation.

Amnon
There goes my subtle hinting...
Amnon
A: 

I have never heard the term inversion used in this way.

A decreasing array of length N, for N>0, has 1/2*N*(N-1) pairs i<j with A[i]>A[j]. This is the maximum possible.

Charles Stewart
http://mathworld.wolfram.com/PermutationInversion.html
Petar Minchev
@Petar: Thanks. I think Knuth doesn't use the term.
Charles Stewart
+1  A: 

Clearly N, ..., 2, 1 has the highest number of inversions. Every pair is an inversion. For example for N = 6, we have 6 5 4 3 2 1. The inversions are 6-5, 6-4, 6-3, 6-2, 6-1, 5-4, 5-3 and so on. Their number is N * (N - 1) / 2.

Petar Minchev
aha I get it also thanks for your link mathworld.wolfram.com/PermutationInversion.html
also is this correct that if the array is more in order its inversion will be more???
More in order is not a defined term. But intuitively a permutation which is more reversed will probably have more inversions than a non-reversed. But again it depends on the permutations you compare.
Petar Minchev
aha !!thanks :)