Log In

Diff sort

Posted on: February 27th, 2014 by
1

You are given an array of n real numbers. Arrange them so that the average difference between adjacent numbers is minimized. In other words, minimize {1\over n-1}\sum_{i=1}^{n-1} |X[i]-X[j]|.

- via Algorithmic puzzles


One Response to Diff sort

  1. aditya had this to say about that:

    Assuming your "j" stands for "i+1", isn't the answer just arranging all the numbers in ascending (or descending) order? In that case, sum will be Nmax-Nmin; whereas in any other arrangement, the sum will be Nmax-Nmin+something else.


{"result":"error", "message":"You can't access this resource as it requires an 'view' access for the website id = 1."}