Can we express median in terms of standard operations? Given a list of integers $a_1,a_2,...,a_n$ where $n \geq 1$ is odd (may not be in ascending order), is it possible to express their median in terms of some well-known operations such as maximum or minimum?
For example, if we have three numbers, say $3,6,5$, then their median is always the one which is neither the maximum nor minimum. In the example, their median is $5$.
 A: Yes! Write $n=2k+1$. Then the median is the maximum of the minima of all $k+1$ element subsets of the data.
For example, when $n=3$, then there are $\binom{3}2=3$ two element subsets of the data: $\{a_1,a_2\},\{a_1,a_3\},\{a_2,a_3\}$. The median is the max of all these minima:
$$
\text{median}(a_1,a_2,a_3)=\max\big(\min(a_1,a_2),\min(a_1,a_3),\min(a_2,a_3)\big)
$$
When $n=5$, there are $\binom53=10$ three element subsets of the data, so
$$
\text{median}=\max\Big(\min(a_1,a_2,a_3),\min(a_1,a_2,a_4),\min(a_1,a_2,a_5),\min(a_2,a_3,a_4),\dots,\min(a_3,a_4,a_5)\Big)
$$
As you can see, this formula quickly gets unwieldy. The number of terms is $\binom{n}{(n+1)/2}$, which grows exponentially. 
A: The median is the arg min of the sum of absolute deviations of $X_i$ from $\theta.$
Similarly, the mean is analogous for squared deviation.
A: $F(k)=\sum_{r=1}^n |k-a_r| $, (where k is a variabe , $a_r>a_{r+1}$)

If n is odd ,n=2m+1
$k>a_1\Rightarrow$ all mods open as $k-a_r$ and so derivative is >0(as you increase 'k' the value of function increase).
$a_1>k>a_2$ then one mod only open as $a_r-k$(r=1) ,  and others as $k-a_r$, hence still derivative >0
$a_m>k>a_{m+1} $ ,here m+1 mods open as $k-a_r$ and m mods open as $a_r-k$ ,so derivative is greater than 0
So obviusly derivative becomes negative if $k<a_{m+1}$ and derivative is greater than 0 if $k>a_{m+1}$ , hence minimum of the function is at $a_{m+1}$.

If n is even ,n=2m
You will find that derivative is >0 if , $k>a_{m}$
Derivative <0 if $k<a_{m+1}$
Derivative =0 if $ a_m>k>a_{m+1}$ , so the function is minimum for all such $k$(including $a_m$ and $a_{m+1}$).
So for even number of terms we define mode as $\frac{a_m+a_{m+1}}{2}.$
