Q:Describe a Θ(n lg n)-time algorithm that, given a set S of n integers, determines which two elements in S have the smallest difference.
(From what i understand, we first apply merge sort to our list which should take theta(n log n) time. Now as the numbers are sorted, we can compare adjacent members and record their differences keeping track(possibly using an array). This should take theta(n) time. Therefore the overall running time will still be of order theta(n log n).Is this explanation valid?
This isn't recursive, but:
Since sorting takes $\Theta(n \log n)$ time, sort $S$.
Then go through the sorted list, looking at the difference between consecutive items. The smallest difference is what you want. This last step takes $\Theta(n)$ time, so the total time is still $\Theta(n \log n)$.