How to find minimum value of $$|x-1| + |x-2| + |x-31| + |x-24| + |x-5| + |x-6| + |x-17| + |x-8| + \\|x-9| + |x-10| + |x-11| + |x-12|$$ and also where it occurs ?
I know the procedure for find answer for small problems like the following
what is the minimum value of |x-2| + |x+3 | + |x-5| and where it occurs ?
Here it is easy to visualise and give answer or even possible mathematically using equations as
Let the point be at distance c from $x = -3$ so the sum of the distances from the $3$ points $x =2$ , $x=-3$ , $x=5$ are $5-c$ , $8-c$ and $c$ respectively ,so total distance is minimum when it is 8 as $x=-3$ and $x=5$ are the farthest and they are $8$ units away so the required point must lie within this region so
$$ 5-c + 8-c + c = 8 $$ $$ c = 5 $$ so the point where minimum value occurs is at $x =2$
to find the minimum value substitute it in equation to get value as 8.
But In this problem it is hard to do it this way as there are more points .
Is there any easy way to find the answer .
Thanks
Let's make it generic, you want to minimise
$$f(x) = \sum_{k = 1}^n \lvert x - p_k\rvert,$$
where, without loss of generality, $p_1 \leqslant p_2 \leqslant \ldots \leqslant p_n$.
How does the value of $f(x)$ change if you move $x$
A simple counting argument finds the location of the minimum.