Inversion count application

I just understand this topic…basically inversion count tells us the no. of inversions we need to sort the array(I think we can say like this)…so it can help me to get the min inversions to sort the array??..and also it tells which indexs are getting swapped…?
like if we say we have example - 3 2 1 …so we need 1 inversion that is (3,0) to sort this array and the indexes are 0 and 2(based on 0 based indexing) …so we only need 1 inversion…! please tell how…my problem can be solved with this…!

** so we need 1 inversion (3,1)

@archa_1712
It tells how many swap will be performed in case you did a bubble sort
In 3,2,1 you need swaps
So inversion count will be 3

can we get min swaps to sort the array using this?

@archa_1712
Thats exactly what it tells

https://ide.codingblocks.com/s/229921 //inversion count code
https://ide.codingblocks.com/s/229923 //code from gfg

both giving different outputs for min swaps

@archa_1712
The answer for inversion count for any question is unique
So your code must be wrong

i have done the code from the video it was giving all the answers…

please tell then what’s wrong?

@archa_1712
Which test case did you use ?

1 , 5 ,4 ,3 ,2 …

@archa_1712
The GFG code is for min swaps to sort array
That is not inversion count code

but if see…total no . of swaps requried to sort the array = number of inversions in array …according this i thought if we get the total no. of min inversions then i get the min swaps required to sort the array

@archa_1712
As I told you
Total no . of swaps required to sort the array != number of inversions in array
Please read above

Okay i get your point!
so please one more doubt

please help me to understand this concept and code

@archa_1712
This is actually cycle sort and is a medium-hard concept
I don’t think you’re at that level right now
For now I request you to leave this
Come back to this after your course is atleast 80% done

okay…thanks…

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.