2
$\begingroup$

This question was inspired by this:

Finding a non-piece wise function that gives us the $i$'th largest number.

My question is how to do this for four or more values.

In other words, given 4 values $a, b, c,$ and $d$, specify functions $order_i(a, b, c, d)$ for $i = 1 $ to $4$ such that $order_i(a, b, c, d)$ returns the $i^{th}$ smallest value.

Here is my start as an answer for 4 values:

Define a set of auxiliary functions

$bmin2(a, b) =\frac12(a+b-|a-b|) $, $bmax2(a, b) =\frac12(a+b+|a-b|) $, $bmin3(a, b, c) =bmin2(bmin2(a, b), c) $, $bmax3(a, b, c) =bmax2(bmax2(a, b), c) $, $bmin4(a, b, c, d) =bmin2(bmin3(a, b, c), d) $, $bmax4(a, b, c, d) =bmax2(bmax3(a, b, c), d) $, $bcenter(a, b, c, d) =a+b+c+d-bmax4(a, b, c, d)-bmin4(a, b, c, d) $.

We get the min and max, and we can get the sum of the middle two, but how to separate that sum into the individual values so we can we can decide which is smaller is not immediately clear to me.

As to doing this for 5, oy!

And, for general $n$, I have no idea.

$\endgroup$
1
  • $\begingroup$ Yep. Thanks. Fixed. $\endgroup$ Commented Jan 11, 2015 at 23:18

1 Answer 1

0
$\begingroup$

$max (a,b,c,d)= max(max(a,b),max(c,d))$

$min(a,b,c,d)=min(min(a,b),min(c,d))$

the second largest object is $min(max(a,b,c),max(a,c,d),max(a,b,d),max(b,c,d))$

the second smallest is $max(min(a,b,c),min(b,c,d),min(a,c,d))$

All of the previous functions can be expressed as polynomials.

Apply a Lagrange polynomial to put everything together.


There is a more general approach for $n$ objects.If you want to find the $k'th$ largest element you can just take the min over the max of all the subsets of size $n-k+1$. The subsets with the smallest max is precisely the one which does not have any of the largest $k-1$ elements, and hence the max of that subset is the $k$ largest number.

$\endgroup$
3
  • $\begingroup$ Nice! How about five? $\endgroup$ Commented Jan 12, 2015 at 2:52
  • $\begingroup$ There is a more general approach for $n$ objects.If you want to find the $k'th$ largest element you can just take the min over all the subsets of size $n-k+1$ $\endgroup$
    – Asinomás
    Commented Jan 12, 2015 at 2:57
  • $\begingroup$ The subsets with the smallest max is precisely the one which does not have any of the largest $k-1$ elements, and hence the max of that subset is the $k$ largest number. $\endgroup$
    – Asinomás
    Commented Jan 12, 2015 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .