64

There are $25$ horses with different speeds. My goal is to rank all of them, by using only runs with $5$ horses, and taking partial rankings. How many runs do I need, at minimum, to complete my task?

As a partial answer, I know that is possible to determine the first $3$ horses with $7$ runs, and, by a slight generalization of the optimal algorithm used to find the first three, have the complete ranking in $20$ runs.

Is it possible to do better?

What if we have $n$ horses and want to rank them with runs with $k$ horses?

Simon Fraser
  • 2,528
Jack D'Aurizio
  • 353,855
  • 9
    You'll need at the very least $\log(25!)/\log(5!)\gt12$ runs. – joriki Oct 09 '12 at 10:37
  • 7
    Use stopwatch and then 5 runs are enough.. – Berci Oct 09 '12 at 11:15
  • 7
    You seem to have a transitive tournament on 25 nodes, do not know the edge directions, and are sampling 5-vertex induced subgraphs until you find all the edge directions. It might be that a "dynamic" scheme (where we can adjust our decisions based on knowledge of earlier partial rankings) might be better than a "static" scheme; is this allowed? – Douglas S. Stones Oct 09 '12 at 13:17
  • 2
    Yes, dynamic schemes are allowed, and, in fact, my solution in 20 runs is dynamic. – Jack D'Aurizio Oct 09 '12 at 14:16
  • 3
    I have an update. If we start with 5 runs with all the 25 horses, and at least 2 of the first 4 horses run together in one of the 5 initial runs, we can find the first 5 horses with 8 runs only. This leads to an adaptive algorithm that gives the complete ranking in about 18.5 runs (average), 20 runs (worst). – Jack D'Aurizio Oct 09 '12 at 16:24
  • 2
    Finding the top three horses was (will have been? it's a later question...) discussed at http://math.stackexchange.com/questions/56159/number-of-races-needed – Gerry Myerson Jan 24 '13 at 03:13
  • 3
    With $k=2$, this is problem is actually equivalent to a standard sorting algorithm. quicksort is I think the best one and runs in $n\log_2n$. – Tom-Tom May 07 '15 at 09:35
  • 1
    @Tom-Tom quicksort is not necessarily the best regarding the absolute count of (best/average/worst case) comparison operations. But as there are $n!$ possible orders and each comparison gives us at most one bit of info, we certainly need at least $\log_2 n!\approx\log_2( n^ne^{-n}\sqrt{2\pi n})\sim n\log_2 n$ – Hagen von Eitzen Sep 25 '19 at 22:13
  • For $k=2$ and $n \leq 15$ the optimal number of "runs" is here: https://oeis.org/A036604 – Dmitry Kamenetsky Mar 01 '21 at 12:27
  • In the best case, you will only need 6 runs! Let $h_i$ be the i-th horse. Suppose the true speeds are $h_p < h_q \forall p<q$. In the first $k \leq 5$ runs, run horses $h_{5k-4}$ to $h_{5k}$. On the 6-th run, run $(h_5, h_{10}, h_{15}, h_{20}, h_{25})$, which will finish in that order. Now you have the full ordering. So I think this question needs to be asking the minimum number of runs required in the WORST case. – Dmitry Kamenetsky Mar 01 '21 at 12:34
  • @DmitryKamenetsky: $v_1 < v_2 < v_3 < v_4 < v_5$ and $v_6 < v_7 < v_8 < v_9 < v_{10}$ together with $v_5 < v_{10}$ do not ensure $v_9 < v_5$ or the opposite, so $6$ runs are not enough to get a complete ranking. – Jack D'Aurizio Mar 24 '21 at 12:57
  • @JackD'Aurizio my friend pointed me to a strategy that does work in 6 runs, it is just very unlikely to happen. run 1: $h_1<h_2<h_3<h_4<h_5$, run 2: $h_5<h_6<h_7<h_8<h_9$, run 3: $h_9<h_{10}<h_{11}<h_{12}<h_{13}$, run 4: $h_{13}<h_{14}<h_{15}<h_{16}<h_{17}$, run 5: $h_{17}<h_{18}<h_{19}<h_{20}<h_{21}$, run 6: $h_{21}<h_{22}<h_{23}<h_{24}<h_{25}$. – Dmitry Kamenetsky Jun 18 '21 at 05:53

1 Answers1

5

Just some lower and upper bounds.

There must be at least $13$ races, because you need $25!$ possible results, all the possible orderings of the $25$ horses - and there are only $120=5!$ results in each race. Since $120^{12}<25!<120^{13},$ you definitely cannot do it in $12$ races.

With $n$ horses and races of $k$ horse, you need at least: $$\left\lceil \log_{k!}(n!)\right\rceil$$ races.

(When $k=2,$ this is the usual minimum of $\log_2(n!)\approx n\log_2 n-n$ comparisons to do a complete sorting of a list.

It can definitely be done in $30$ races, by considering all 30 lines in the finite affine plane $\left(\mathbb Z/5\mathbb Z\right)^2.$ That is definitely overkill - every horse is raced against every other horse.

Thomas Andrews
  • 177,126
  • Could you explain why it's $k!^x$ please? (where x is the number of races). I think I understand that each race/comparison produces k! results because that's the number of permutations possible for each comparison but why multiply consecutive results? When solving by logic, some races produced more information than others so I'm confused. – tiktok Nov 20 '21 at 07:23
  • $k!$ is just the maximum amount of “information” you can get from an additional race. If two races share a pair of horses, then the second race provides less additional information. This is why these values are lower bounds. @tiktok – Thomas Andrews Nov 20 '21 at 15:24
  • 1
    Specifically, after $m$ races of size $k,$ we get a total of at most $(k!)^m$ different results. But to determine all $n!$ ways of ordering $n$ horses, we need at least $n!$ different results, so we need $(k!)^m\geq n!,$ or $m\geq\log_{k!}(n!).$ – Thomas Andrews Nov 20 '21 at 15:33