This is simple.......
during recursive step of merging...
lets say you have two array left and right (both are sorted) and you are
going to merge it.
l[i] represent the element of left arrray
r[j] represent the element of right array
if (r[j] < l[i]) {
increase the inversion count by the number of elements lefts in left array
put element r[j] into merged array
j++
} else {
no increase in count, just put the element r[i] into merged array
i++;
}
On Sun, Apr 24, 2011 at 5:03 AM, vishwakarma <[email protected]>wrote:
> u can use BIT(Binary Indexed Tree) to count inversions.
> I prefer this becoz it is much easier to code BIT than merge sort.
>
> On Apr 24, 4:25 am, سهراب ابوالفتحی <[email protected]>
> wrote:
> > Let A[1..n] be an array of n distinct numbers. If i < j and A[i] > A[j],
> > then the pair (i,j) is called an inversion of A. Give an algorithm that
> > determines the number of inversions in any permutation on n elements in
> > tetta(n lg n) worst-case time. (with Modify merge sort.)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
Saif Hasan
http://stab-iitb.org/wncc
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.