2 2 votes Suppose in an array A[] , we exchange elements A[i] and A[i+k] , which were originally out of order A) at least 1 and at most 2k-1 inversions are removed B) at least 2 and at most 2k inversions are removed C)at least 0 and at most k inversions are removed D) none Algorithms algorithms sorting testbook-test-series + – Raj_Choudhary 1.1k views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply srestha commented Nov 22, 2017 reply Follow flag Ans is A is it? 0 0 replyShare Raj_Choudhary commented Nov 22, 2017 reply Follow flag @srestha YES but how ? 0 0 replyShare Ashwin Kulkarni commented Nov 22, 2017 reply Follow flag Please can you explain the logic? 0 0 replyShare srestha commented Nov 22, 2017 reply Follow flag Suppose i=0 and k=1 So, we want to inversion of a[0] and a[1], which can be done in with 1 inversion Now index k>=i So, maximum i=k index of a[i+k]=a[k+k]=a[2k] So, maximum inversion from 0 th index is 2k-1 1 1 replyShare Please log in or register to add a comment.
Best answer 2 2 votes Elements 5 4 3 2 1 Inversions 4 3 2 1 0 Total Inversions = 4+3+2+1+0 =10 for minimum, let k=1 , swap(a[0],a[0+1]) Elements 4 5 3 2 1 Inversions 3 3 2 1 0 Total Inversions = 3+3+2+1+0 =9 difference =1 2. now, let k= 2, swap(a[0],a[0+2]) Elements 3 4 5 2 1 Inversions 2 2 2 1 0 Total Inversions = 2+2+2+1+0 =7 difference =3 From 1 and 2: Option A satisfies. Akash Mittal answered Nov 22, 2017 • selected Nov 25, 2017 by Raj_Choudhary Akash Mittal comment Share Follow 0 reply Please log in or register to add a comment.