Algorithm for finding number of inversion in array