So I am looking for an algorithm that can help me with a task.
I have $n$ Natural (positive intiger) numbers. I want to make a list of their pairs.
There are $n\choose2$ pairs, which is $O(n^2)$.
I want to make a list of these pairs by the absolute value of the subtraction.
so for example if my list is $(1,2,4,9)$ the output result would be:
I am looking for an algoritm that would do so in $O(n^2)$. You can assume the list
is sorted at the beginning, any way its a matter of only $O(nlogn)$.
Thanks a lot!