I want to extract useful info from some data and this makes me think how to do it efficiently. I will try to explain the problem with math terms.
If we have a sequence of numbers $A=(a_{1}\space a_{2}\dots a_{n})$ and we want to count the number of inversions, ie the number of pairs $(a_{i},a_{j}), 1\leq i < j\leq n$ and $a_{i}>a_{j}$.
I want to find a good algorithm that will solve this problem.
I am looking for an algorithm that is better from the trivial one that solves the problem in polynomial time.