Algorithm for counting inversions — Pre-requisites: Good knowledge of programming Familiarity with recursion Familiarity with algorithms What are Inversions? Inversion in a list of numbers indicates how far a list is from being sorted. Let us say we have a variable: arr = [1,2,4,3,5,6], in the variable arr we have one inversion of the numbers 4 and 3 because…