The Gini coefficient is often used in economics to calculate inequality.
According to this website, the formula for calculating Gini coefficient is
$G = \frac{\sum_{i=1}^{n} \sum_{j=1}^{n} |x_i - x_j|}{2n^2\bar{x}}$
However, if all values are arranged in ascending order, computation is quicker:
$G = \frac{2}{n^2\bar{x}} \sum_{i=1}^{n}i(x_i-\bar{x})$
Why does the last formula work?