1

Given $a_1 < a_2 < ... < a_n$ and $f(x) = \sum_{i=1}^n |x - a_i|$, find a minimum

I had to look up the answer for this, and when I did, I still have some questions

It starts off by considering some $x$ and $y$ that are equidistant from some $a_j$

enter image description here

1/ My first question is philosophical, and is in regards to why would one's thinking lead them to this approach when solving this problem. "I should consider what is happening to equidistant points around some $a_j$"

Next, they produce two equations:

If we consider some $a_i$ where $i \leq j - 1$, then we have

$$|y - a_i| = |x - a_i| + |y - x|, \space \forall i \leq j - 1$$

This makes sense

Now, we consider what happens for some $a_i$ where $i \geq j + 1$

2/ Now my second question concerns why we skipped over $j$. Provided I independently arrived at this step, I would not have thought to skip over an index.

$$|y - a_i| = |x - a_i| - |y - x|, \space \forall i \geq j + 1$$

The solution itself then goes on to say

$$f(y) = f(x) + |y - x| \cdot ((j - 1) - (n - j)) = f(x) + |y - x| \cdot (2j - n -1)$$

3/ How do we get this result

While I don't know how to answer my previous two questions, I attempted to answer this question. We must consider what happens to the function on three separate intervals: $[a_1, a_{j-1}]$, ??, $[a_{j+1}, a_n]$

$$ \begin{equation} \begin{aligned} f(y) = \sum_{i=1}^n |y - a_i| &= \sum_{i=1}^{j-1} \left(|x - a_i| + |y - x|\right) + \sum_{j+1}^n \left( |x - a_i| - |y -x| \right) + ?? \\ & = (j - 1)|y - x| + \sum_{i=1}^{j-1} |x - a_i| - (n-j)|y-x| + \sum_{i=j+1}^n |x - a_i| + ?? \\ & = f(x) + |y -x|(2j - n -1) \end{aligned} \end{equation} $$

And final question, which relates to question 1/

4/ How do we know that the two equations produced due to 1/ hold unique and distinct pieces of information about the original function that will yield fruitful result and not just cancel each other out. Because naively, you could argue that if you add those two equations together you get back a known result that $|y - a_i| = |x - a_i|$. If I independently arrived at those two equations, after having added them together and getting back this result, I would have likely not pursued this avenue further.

naz
  • 3,509

1 Answers1

0

I start by giving you a simpler solution which maybe can answer some of your questions:

this function is piecewise linear, the nonlinearity points being the points $a_i$. This directly implies that the minimum will be attained at one of the points $a_i$. If you calculate the derivative you will find the function being decreasing until you reach a point $a_j$, for j being the smallest integer s.t. $2j\geq n$.

Going back to your questions:

3\ you get that by writing the function term to term and you write each term of $y$ in function of $x$, as you found previously.

2\ this is useful to find 3, and you skipped point $j$ because $x$ and $y$ are equidistant from it.

1\ number \2 explains this choice of $x$ and $y$

Giann
  • 66