Explanation of sorting algorithm