0

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

user355002
  • 871
  • 2
  • 10
  • 22
  • Based on your previous questions, I am tagging this as homework. Feel free to remove it, if it is not. If it is homework, I suggest you leave it, as people will be more helpful (to your understanding of the subject matter) if you have any doubts etc. –  Jun 20 '10 at 14:44
  • it is not my home work but I need people to be more helpful so I save this tag :) – user355002 Jun 20 '10 at 15:20

3 Answers3

1

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
  • 46,889
  • 11
  • 103
  • 119
  • aha I get it also thanks for your link mathworld.wolfram.com/PermutationInversion.html – user355002 Jun 20 '10 at 15:26
  • also is this correct that if the array is more in order its inversion will be more??? – user355002 Jun 20 '10 at 15:31
  • 1
    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 Jun 20 '10 at 15:39
0

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
  • 7,652
  • 2
  • 26
  • 34
0

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
  • 11,661
  • 4
  • 46
  • 85