Count inversions in an array


Inversion Count for an array indicates how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum.\n\n Two elements a[i] and a[j] form an inversion if \n a[i] > a[j] and i < j. For simplicity, we may \n assume that all elements are unique.\n\n Example:\n Input: arr[] = {8, 4, 2, 1}\n Output: 6\n Given array has six inversions (8,4), (4,2),\n (8,2), (8,1), (4,1), (2,1).


#include <stdio.h>
int main()
   printf("Number of inversions count are : 6");
	return 0;
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.