# Tag Archives: inversion

## Counting cross lines in an arrayNovember 5, 2017

Given an unsorted array of distinct elements. Task is to count number of cross lines formed in an array elements after sorting the array elements.… Read More »

## Counting inversions in all subarrays of given sizeOctober 17, 2017

Given an array and an integer k, count all inversions in all subarrays of size k. Example: Input : a[] = {7, 3, 2, 4,… Read More »

## Subarray InversionsAugust 10, 2017

We have an array A of n integers that we’re planning on sorting. Specifically, we want to know how close the array is to sorted.… Read More »

## Minimum swaps to reach permuted array with at most 2 positions left swaps allowedMarch 26, 2017

Given a permuted array of length N of first N natural numbers, we need to tell the minimum number of swaps required in the sorted… Read More »

## Sorting possible using size 3 subarray rotationMarch 8, 2017

Given an array of integer values which need to be sorted by only one operation – subarray rotation where subarray size should be 3. For… Read More »

## Count pairs in an array that hold i*arr[i] > j*arr[j]December 15, 2016

Given an array of integers arr[0..n-1], count all pairs (arr[i], arr[j]) in the such that i*arr[i] > j*arr[j], 0 =< i < j < n.… Read More »

## Number of swaps to sort when only adjacent swapping allowedNovember 25, 2016

Given an array arr[] of non negative integers. We can perform a swap operation on any two adjacent elements in the array. Find the minimum… Read More »

## Number of permutation with K inversionsNovember 10, 2016

Given an array, an inversion is defined as a pair a[i], a[j] such that a[i] > a[j] and i < j. We are given two… Read More »

## Find Surpasser Count of each element in arrayJuly 9, 2016

A surpasser of an element of an array is a greater element to its right, therefore x[j] is a surpasser of x[i] if i <… Read More »

## Count Inversions of size three in a given arrayDecember 21, 2015

Given an array arr[] of size n. Three elements arr[i], arr[j] and arr[k] form an inversion of size 3 if a[i] > a[j] >a[k] and… Read More »

## Count inversions in an array | Set 3 (Using BIT)December 18, 2015

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count… Read More »

## Count inversions in an array | Set 2 (Using Self-Balancing BST)December 17, 2015

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count… Read More »

## Time complexity of insertion sort when there are O(n) inversions?November 22, 2014

What is an inversion? Given an array arr[], a pair arr[i] and arr[j] forms an inversion if arr[i] < arr[j] and i > j.

## Count Inversions in an array | Set 1 (Using Merge Sort)January 5, 2010

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count… Read More »