betaFeedback

WorksComputer Science

Selecting the 7th Smallest of 16 Elements Takes Exactly 28 Comparisons

Abstract

Let Vi(n)V_i(n) denote the minimum worst-case number of comparisons needed to find the ii-th smallest of nn distinct elements. We construct algorithms showing V7(16)≤28V_7(16)\le28 and V8(16)≤29V_8(16)\le29, improving the previously reported upper bounds of 30 and 31. Together with known lower bounds, these results establish V7(16)=28V_7(16)=28 and leave V8(16)∈{28,29}V_8(16)\in\{28,29\}. For 17 elements, we establish V5(17)=27V_5(17)=27 and improve the upper bounds for ranks 6 through 9 to 29, 30, 31, and 31, respectively. Every new upper bound has an explicit decision-graph certificate verified by a static checker developed independently of the search. We also derive a lower bound for selection from a partially ordered state by combining the Fussenegger-Gabow weight with its order-reversed counterpart. All new upper bounds and this lower bound are formally verified in Lean 4. For V8(16)V_8(16), we show that a lower bound based solely on the total number of decision-tree leaves cannot establish V8(16)≥29V_8(16)\ge29. The algorithms were found using fixed-budget search, information-guided comparison ordering, and proof-number search. Proof-number search was decisive in finding the 28-comparison algorithm; in our experiments, refuting a comparison budget remained substantially more expensive than finding an algorithm within it.

Introduction

Selection asks for the element of a given rank using as few pairwise comparisons as possible. Write Vi(n)V_i(n) for the smallest worst-case number of comparisons needed to find the ii-th smallest of nn distinct elements. Reversing the order shows Vi(n)=Vn+1−i(n)V_i(n) = V_{n+1-i}(n). Classical results include V1(n)=n−1V_1(n) = n - 1 and V2(n)=n−2+⌈log⁡2n⌉V_2(n) = n - 2 + \lceil\log_2 n\rceil (Kislitsyn; see [12]), and the general upper bound of Hadian and Sobel [10], Vi(n)≤n−i+(i−1)⌈log⁡2(n+2−i)⌉V_i(n) \le n - i + (i - 1)\lceil\log_2(n + 2 - i)\rceil.

Asymptotically, selection takes linear time [2], but even the leading constant for the median is open [3, 7, 6].

Small exact values have been determined by computer search, starting with Gasarch, Kelly and Pugh [9] and Oksanen [14, 15]. Dörrer et al. [5] settled all entries for n≤15n \le15 and the first six ranks for n=16n = 16. The two remaining 16-element entries had lower bound 28; with the upper bounds reported in [9 Table 3], the ranges were 28≤V7(16)≤3028 \le V_7(16) \le30 and 28≤V8(16)≤3128 \le V_8(16) \le31.

Theorem 1. V7(16)=V10(16)=28V_7(16) = V_{10}(16) = 28.

Theorem 2. V8(16)=V9(16)≤29V_8(16) = V_9(16) \le29. Hence V8(16)∈{28,29}V_8(16) \in\{28, 29\}.

Theorem 3. V5(17)=V13(17)=27V_5(17) = V_{13}(17) = 27. Moreover V6(17)≤29V_6(17) \le29, V7(17)≤30V_7(17) \le30, V8(17)≤31V_8(17) \le31, and V9(17)≤31V_9(17) \le31.

Our contribution to all three theorems is the upper bounds. The lower bound of Theorem 1 is the entry 28–33 of [5 Table 3], obtained there by computer search; we use it without rederiving it. The lower bounds V8(16)≥28V_8(16) \ge28 and V5(17)≥27V_5(17) \ge27 follow from the published values V8(15)=27V_8(15) = 27 and V5(16)=26V_5(16) = 26 [5] and the transfer lemma of § 2. Table 1 and Table 2 show the previous and new ranges. The table in [5] lists the Hadian–Sobel values 33 and 36 for the two open 16-element entries; the upper bounds 30 and 31 of [9] are smaller and are the baseline we improve.

ii12345678
before [5, 9]15182124262728–3028–31
this paper1518212426272828–29

Table 1. The row n=16n = 16 of the selection table.

ii123456789
before1620222527–2828–3129–3329–3429–35
this paper162022252728–2929–3029–3129–31

Table 2. The row n=17n = 17. Lower bounds: classical formulas for i≤2i \le2, otherwise the row n=16n = 16 of [5] with the transfer lemma. Previous upper bounds: Hadian–Sobel for i≤4i \le4 and [9 Table 3] for $i \ge 5.

Contributions and evidence

  1. Seven new upper bounds, each witnessed by an explicit certificate (§ 3). A static checker that shares no code with the search accepts every certificate, and the Lean 4 kernel checks a formal proof of every bound.

  1. A description of the 15-comparison opening shared by several of the new algorithms (§ 4).

  1. A lower bound for selection from a partial order, combining the weight of Fussenegger and Gabow [8] with its order-reversed counterpart (§ 5), with a formal proof in Lean 4 for all finite partial orders.

  1. A search method that made the constructions practical (§ 6).

Statements that rest only on search runs, such as refutations under a fixed opening, are labeled as such and are not used in any theorem.

Preliminaries

A selection problem is a strict partial order PP on a set Ω\Omega of nn elements, recording the comparisons known so far and their transitive consequences, together with a rank ii. Write Vi(P)V_i(P) for the minimum worst-case number of further comparisons. We write EnE_n for the empty order on nn elements (the antichain), in which nothing is known. Since an algorithm starts in this state, Vi(n)=Vi(En)V_i(n) = V_i(E_n) by definition. The inputs are totally ordered, but the algorithm knows only PP. Two elements whose order is not yet known, that is, not implied by PP, are called incomparable, written a∥ba \parallel b; only such pairs are worth comparing. P+abP + ab denotes the transitive closure of PP with a<ba < b added. For an unsolved problem

Vi(P)=1+min⁡a∥bmax⁡{Vi(P+ab),Vi(P+ba)},V_i(P) = 1 + \min_{a \parallel b}\max\{V_i(P + ab), V_i(P + ba)\},

and Vi(P)=0V_i(P)=0 once some element is known to have exactly i−1i-1 elements below and n−in-i above it.

An element with at least ii known predecessors is too large to be the answer, and one with at least n−i+1n-i+1 known successors is too small. Deleting such an element does not change the optimal cost [5]; deleting a too-small element lowers the rank by one. Problems that are isomorphic, or dual under order reversal with rank n+1−in+1-i, have the same cost.

Transfer lemma [5 Lemma 1]. For 1≤i≤n1 \le i \le n,

Vi(n+1)≥Vi(n)+1,Vi+1(n+1)≥Vi(n)+1.V_i(n+1) \ge V_i(n)+1,\qquad V_{i+1}(n+1) \ge V_i(n)+1.

For the first inequality, run an algorithm for rank ii of n+1n+1 elements on the nn given elements and an artificial element larger than all of them, answering comparisons with that element without cost. It returns the ii-th smallest given element. On every path the artificial element must be compared at least once, since it must end up known to lie above the answer, so every path saves at least one comparison. An artificial smallest element gives the second inequality.

Certificates and their verification

Certificates

We use the standard decision-tree model [12 Sec. 5.3]. For fixed nn, a deterministic algorithm that accesses the elements only through comparisons corresponds to a binary tree: each internal node compares two elements and branches on the outcome, and each leaf returns an element. An input follows a single root-to-leaf path, so the worst-case number of comparisons is the depth of the tree, and Vi(n)V_i(n) is the minimum depth of a tree that always returns the ii-th smallest element. An upper bound Vi(n)≤kV_i(n) \le k is therefore proved by exhibiting one such tree of depth at most kk; a lower bound must hold for every such tree. Merging identical subtrees turns the tree into a directed acyclic graph. Our certificates are such graphs, written as Rust programs in the format of the search code of [5]. Each function solves a remaining subproblem: it may compare two arguments, discard arguments that cannot be the answer, and call another function on the remaining ones. A doc comment declares the size, the 0-based rank, and known relations. For example, this function from the 28-comparison certificate finds the median of three elements when b<cb<c is known:

/// n = 3, i = 1, b < c
fn select_12([a, b, c]: [usize; 3]) -> usize {
    if a < b { select_1([b]) } else { select_2([a, c]) }
}

If a<ba<b, then a<b<ca<b<c and bb is returned. Otherwise bb is below both aa and cc, so it is discarded and the minimum of aa and cc is found with one more comparison. The root function select_0 receives all inputs with no known relations.

The static checker and why it is sound

The checker was written from the mathematical definitions without access to the search code, and accepts only a narrow grammar. It never uses the relations stated in comments. Instead it propagates knowledge from the root: each comparison outcome is added and closed transitively, and arguments are mapped to the callee’s names. A function called from several places gets as its precondition PfP_f the relations that hold at every call site; this can only make acceptance harder. Under PfP_f and each branch outcome it requires:

  1. compared elements are incomparable before the comparison (this rejects wasted comparisons; soundness does not need it);

  1. each call passes the declared number of pairwise distinct arguments;

  1. each discarded element is certainly below the requested 0-based rank rr among mm elements (at least m−rm-r known successors) or certainly above it (at least r+1r+1 known predecessors);

  1. the callee’s declared rank equals rr minus the number of discarded elements below;

  1. a directly returned element has exactly rr known predecessors and m−1−rm-1-r known successors.

It also checks that every function is reachable, the root is never called, and the call graph is acyclic.

Soundness. Call ff correct if for all distinct inputs whose order extends PfP_f it terminates and returns the element of its declared rank. By induction in reverse topological order, which exists because the call graph is acyclic: an input of ff follows one checked branch; a returned element is correct by rule 5; for a call, the arguments are distinct inputs (rule 2) that satisfy the callee’s precondition, since that precondition was computed from what every caller knows; and rules 3 and 4 show that the callee’s answer is the caller’s answer. Termination follows from acyclicity. The root has the empty precondition, so the program is correct on all inputs.

Comparison bound. Each input follows a single path from the root to a return and makes only the comparisons on that path. The worst case is therefore the largest number of comparisons on any path, not the size of the graph. The checker computes it backward: a return costs 0, and a comparison costs one more than the larger cost of its two branches. Paths that no input can follow only make this bound larger, so it remains a valid upper bound.

Tests. The checker accepts all 70 optimal algorithms published with [5] with exactly their known costs, and rejected every wrong or ill-formed program among 12,046 generated mutants. An independently written exact oracle, following every path without intersecting preconditions, confirms each of our certificates and finds that its exact worst case equals the checker’s bound. Each certificate also passes 2⋅1072 \cdot10^7 compiled executions on pseudorandom permutations.

Formal proofs in Lean

A Lean 4 development formalizes the same argument. It uses only Lean’s core library, so every definition the theorems depend on is contained in our own short specification. It defines programs of this kind, their execution with a comparison counter, and the predicate SelectsWithin(Q,n,r,w): on every list of nn distinct natural numbers, program QQ returns an input with exactly rr smaller inputs, using at most ww comparisons. Programs access inputs only by comparing them and passing them on, so they are comparison algorithms, and replacing nn distinct elements of any totally ordered set by their ranks 0,…,n−10,\ldots,n-1 leaves every execution unchanged. The development proves that acceptance by a checker implies the predicate, and the kernel evaluates that checker on the certificate data, giving

∃Q SelectsWithin(Q,n,r,w)for(n,r,w)∈{(16,6,28),(16,7,29),(17,4,27),(17,5,29),(17,6,30),(17,7,31),(18,8,31)}.\exists Q\ \mathrm{SelectsWithin}(Q,n,r,w)\quad\text{for}\quad(n,r,w)\in\left\{(16,6,28),(16,7,29),(17,4,27),(17,5,29),(17,6,30),(17,7,31),(18,8,31)\right\}.

The proofs use only the standard axioms propext, Classical.choice and Quot.sound, not native_decide, and they replay in the independent kernel checker leanchecker. The bounds do not depend on the tool that translates the Rust certificates into Lean: the theorems concern the translated programs themselves, and each is a valid witness. Only the further claim that these programs are the archived Rust files depends on the translation. We cross-checked it against an independent parser and interpreter. The lower-bound theory of § 5 is formalized in a separate development described there.

The 28-comparison algorithm

The 329-function certificate opens with 15 comparisons that reach the same partial order on every input, followed by an irregular endgame of at most 13 comparisons. Calling the smaller element of a comparison its winner: compare eight disjoint pairs; compare the winners of pairs to form four four-element tournaments; then run a tournament among the four losers of these finals, the runner-ups. Each four-element group then has winner ww, its first opponent bb, runner-up rr, and the runner-up’s first opponent dd, with w<bw < b, w<rw < r, r<dr < d. Comparing the runner-ups of two such groups gives R8R_{8}, and comparing the smaller runner-ups of two copies of R8R_{8} gives R16R_{16} (Figure 1). Swapping an outcome only renames components, so every input reaches R16R_{16} after 8+4+3=158 + 4 + 3 = 15 comparisons.

Opening of the 28-comparison algorithm for the 7th smallest of 16

Figure 1. The opening of the 28-comparison algorithm for the 7th smallest of 16. (a) Eight pair comparisons, four group finals, and three comparisons among the runner-ups use 15 comparisons, leaving 13. Both outcomes at each step give the same known order after renaming. (b) The resulting order R16R_{16}. Relations run upward from smaller to larger elements: an upward path gives a known inequality. Edges implied by such paths are omitted. In group XX, wXw_X beat bXb_X and then rXr_X, while rXr_X beat dXd_X. Blue thick edges compare runner-ups, with rA<rBr_A < r_B and rA<rC<rDr_A < r_C < r_D. (c) The next two comparisons. Each box shows (remaining elements, requested rank) and comparisons left; “drop” names newly discarded elements. The left branch is worked through in the text.

For example, the 16th comparison is rBr_{B} against bCb_{C}. If rB<bCr_{B} < b_{C}, then wAw_{A} lies below the ten elements rAr_{A}, dAd_{A}, bAb_{A}, rBr_{B}, dBd_{B}, bCb_{C}, rCr_{C}, dCd_{C}, rDr_{D}, dDd_{D}, so it cannot be the 7th smallest; it is discarded, leaving the 6th smallest of 15 with 12 comparisons. We found no short set of rules describing the endgame. The second 28-comparison certificate and the 252-function 29-comparison certificate for the 8th smallest also pass through R16R_{16}. The opening is not optimal for every rank: the bound of § 5 excludes ranks 1–3, and for the 8th smallest our search finds no 28-comparison completion (a search-level result), so R16R_{16} is optimal there only if V8(16)=29V_{8}(16) = 29.

Lower bounds from a partially ordered state

This section bounds from below the number of comparisons Vi(P)V_i(P) that are still needed once some comparisons are known. Such bounds let the search discard states whose remaining budget is provably too small. We combine two classical weights into a new bound on the number of leaves of every correct decision tree (Theorem 5), recall a bound that follows a single input (Theorem 6), show that the combined weight is the best in a natural family (Proposition 8), and explain why no leaf count alone can settle V8(16)V_8(16) (Remark 9).

A binary tree of depth dd has at most 2d2^d leaves, so a lower bound NN on the number of leaves of every correct tree gives Vi(P)≥⌈log⁡2N⌉V_i(P) \ge\lceil\log_2 N\rceil.

A compatible solution is a triple (L,e,U)(L,e,U) with ∣L∣=i−1|L| = i - 1 such that some total order extending PP lists LL, then ee, then UU; let C(P)C(P) be their set. At a correct leaf the known relations determine the sets below and above the returned element ee: otherwise ee could be placed directly after its known predecessors in one consistent total order and directly before its known successors in another, giving different ranks. Hence distinct solutions need distinct leaves and Vi(P)≥⌈log⁡2∣C(P)∣⌉V_i(P) \ge\lceil\log_2 |C(P)|\rceil [5 Thm. 6]. This is weak: finding the minimum of four elements has four solutions but needs three comparisons, because each non-minimum must lose once.

Weights. A down-set contains all known predecessors of its members; let Dj(P)\mathcal{D}_j(P) be the down-sets of size jj. For L∈Di−1(P)L \in\mathcal{D}_{i-1}(P), the possible answers are the minimal elements of Ω∖L\Omega\setminus L; let b(L)b(L) be their number minus one. For A∈Di(P)A \in D_i(P), the possible answers are the maximal elements of AA; let a(A)a(A) be their number minus one. A solution corresponds to LL and A=L∪{e}A = L \cup\{e\}, so ∣C(P)∣=∑L(b(L)+1)=∑A(a(A)+1)|C(P)| = \sum_L(b(L) + 1) = \sum_A(a(A) + 1). Define

FG(P)=∑L∈Di−1(P)2b(L),FGδ(P)=∑A∈Di(P)2a(A),Φ∗(P)=FG(P)+FGδ(P)−∣C(P)∣.\mathrm{FG}(P) = \sum_{L \in D_{i-1}(P)} 2^{b(L)}, \qquad\mathrm{FG}^{\delta}(P) = \sum_{A \in D_i(P)} 2^{a(A)}, \qquad\Phi^*(P) = \mathrm{FG}(P) + \mathrm{FG}^{\delta}(P) - |C(P)|.

Fussenegger and Gabow [8 Thm. 2(b)] give a weight of this kind for arbitrary partial orders (stated for the largest elements); after reversing the order, their weight is at most FG(P)\mathrm{FG}(P), with equality when no comparisons are known. The code of [5] computes max⁡(FG,FGδ)\max(\mathrm{FG},\mathrm{FG}^{\delta}). The new element is the combination Φ∗\Phi^*. For the minimum of four elements, FG=8\mathrm{FG} = 8, FGδ=4\mathrm{FG}^{\delta} = 4, ∣C∣=4|C| = 4, and Φ∗=8\Phi^* = 8 gives the correct bound 3.

The key step is to follow how a single comparison changes the weight of one fixed lower set LL. After the known order has grown from PP to QQ, the set LL contributes

ψL(Q)={2bQ(L)if L is still a down-set of Q,0otherwise (then L can no longer be the set below the answer),\psi_L(Q) = \begin{cases} 2^{b_Q(L)} & \text{if } L \text{ is still a down-set of } Q,\\ 0 & \text{otherwise (then } L \text{ can no longer be the set below the answer),} \end{cases}

where bQ(L)b_Q(L) is b(L)b(L) computed in QQ. The lemma says that the weight of LL never shrinks in total over the two outcomes.

Lemma 4. Let xx and yy be incomparable in PP, let P1=P+xyP_1 = P + xy and P2=P+yxP_2 = P + yx be the two possible outcomes of comparing them, and fix L∈Di−1(P)L \in D_{i-1}(P).

  1. If both xx and yy lie in LL, the weight is unchanged in both outcomes: ψL(P1)=ψL(P2)=ψL(P)\psi_L(P_1) = \psi_L(P_2) = \psi_L(P).

  1. If exactly one of them lies in LL, one outcome keeps the weight ψL(P)\psi_L(P) and the other sets it to 0.

  1. If neither lies in LL, the two outcomes together keep at least the weight: ψL(P1)+ψL(P2)≥ψL(P)\psi_L(P_1) + \psi_L(P_2) \ge\psi_L(P).

The same holds for an initial set A∈Di(P)A \in D_i(P) with weight 2a(A)2^{a(A)}, with inside and outside exchanged: the weight is unchanged if x,y∉Ax,y \notin A, one outcome keeps it if exactly one of them lies in AA, and the two outcomes together keep at least the weight if x,y∈Ax,y \in A.

Proof. Adding x<yx < y creates only relations u<vu < v with u≤xu \le x and y≤vy \le v. Let M=Ω∖LM = \Omega\setminus L. If x∈Lx \in L, every u≤xu \le x lies in LL, so no relation inside MM and none from MM into LL is created; this gives the first case and the surviving outcome of the second. The outcome placing an element of MM below one of LL destroys LL as a down-set. If x,y∈Mx,y \in M, then LL stays a down-set in both outcomes, and a minimal vv of MM can gain a predecessor in MM only through y≤vy \le v, which forces v=yv = y. So b(L)b(L) drops by at most one in each child, and ψL(P1)+ψL(P2)≥2⋅2b(L)−1\psi_L(P_1) + \psi_L(P_2) \ge2 \cdot2^{b(L)-1}. Order reversal gives the statement for AA.

Theorem 5. Every correct decision tree for (P,i)(P,i) has at least Φ∗(P)\Phi^*(P) leaves. Hence Vi(P)≥⌈log⁡2Φ∗(P)⌉V_i(P) \ge\lceil\log_2 \Phi^*(P) \rceil.

Proof. Removing comparisons with known outcomes does not increase the number of leaves, and at a correct leaf the problem is solved, where FG=FGδ=∣C∣=1\mathrm{FG} = \mathrm{FG}^{\delta} = |C| = 1 and Φ∗=1\Phi^* = 1. It therefore suffices to show Φ∗(P)≤Φ∗(P1)+Φ∗(P2)\Phi^*(P) \le\Phi^*(P_1) + \Phi^*(P_2) for incomparable x,yx,y, and to sum this inequality over the tree. Write ΔF=F(P1)+F(P2)−F(P)\Delta F = F(P_1) + F(P_2) - F(P). Every compatible solution survives in at least one child, the children’s solutions are solutions of PP, and a solution survives in both exactly when xx and yy lie on the same side of its answer. Hence

Δ∣C∣=∑L∈Di−1(P), x,y∈L(b(L)+1)+∑A∈Di(P), x,y∉A(a(A)+1).\Delta|C|=\sum_{\substack{L\in\mathcal{D}_{i-1}(P),\ x,y\in L}}(b(L)+1)+\sum_{\substack{A\in\mathcal{D}_i(P),\ x,y\notin A}}(a(A)+1).

Down-sets of the children are down-sets of PP. By Lemma 4, every LL contributes at least 0 to ΔFG\Delta\mathrm{FG}, and LL with x,y∈Lx,y\in L contributes exactly 2b(L)2^{b(L)}; likewise for ΔFGδ\Delta\mathrm{FG}^{\delta} and AA with x,y∉Ax,y\notin A. Therefore

ΔΦ∗≥∑x,y∈L(2b(L)−b(L)−1)+∑x,y∉A(2a(A)−a(A)−1)≥0,\Delta\Phi^*\geq\sum_{x,y\in L}\left(2^{b(L)}-b(L)-1\right)+\sum_{x,y\notin A}\left(2^{a(A)}-a(A)-1\right)\geq0,

since 2t≥t+12^t\geq t+1.

Theorem 6. Vi(P)≥KEY(P)V_i(P)\geq\mathrm{KEY}(P).

Proof. This is the classical argument about crucial comparisons [12, Sec. 5.3.3], [8], applied along one total order. Answer all comparisons according to a total order extending PP that lists LL, then ee, then UU; let A=L∪{e}A=L\cup\{e\} and M=Ω∖LM=\Omega\setminus L. A new relation inside AA requires a comparison with both ends in AA, since AA is an initial segment of that order, and such a comparison removes at most one maximal element of AA. Dually, only comparisons inside MM remove minimal elements of MM, at most one each. At the end ee must be the only maximal element of AA and the only minimal element of MM, which needs at least asa_s and bsb_s comparisons respectively. As A∩M={e}A\cap M=\{e\}, no comparison is counted twice.

Corollary 7. Vi(P)≥LB(P)=max⁡{⌈log⁡2Φ∗(P)⌉,KEY(P)}V_i(P)\geq\mathrm{LB}(P)=\max\{\lceil\log_2\Phi^*(P)\rceil,\mathrm{KEY}(P)\}. Since 2t≥t+12^t\geq t+1 gives FG,FGδ≥∣C∣\mathrm{FG},\mathrm{FG}^{\delta}\geq|C|, this is never weaker than the compatible-solution bound or either one-sided weight bound.

Within the family ΨF,G=∣C∣+∑LF(b(L))+∑AG(a(A))\Psi_{F,G}=|C|+\sum_L F(b(L))+\sum_A G(a(A)) with F(0)=G(0)=0F(0)=G(0)=0, the choice F(t)=G(t)=2t−t−1F(t)=G(t)=2^t-t-1 gives Φ∗\Phi^*. It is the largest valid member:

Proposition 8. If ΨF,G(En,1)≤2V1(n)\Psi_{F,G}(E_n,1)\leq2^{V_1(n)} and ΨF,G(En,n)≤2Vn(n)\Psi_{F,G}(E_n,n)\leq2^{V_n(n)} for all n≥1n\geq1, then F(t),G(t)≤2t−t−1F(t),G(t)\leq2^t-t-1 for all t≥0t\geq0, and hence ΨF,G≤Φ∗\Psi_{F,G}\leq\Phi^* on every problem.

Proof. For the minimum of EnE_n there is one lower set with b=n−1b=n-1 and nn singleton initial sets with a=0a=0, so n+F(n−1)≤2n−1n+F(n-1)\leq2^{n-1}. The maximum gives the bound for GG. Substituting termwise gives ΨF,G≤Φ∗\Psi_{F,G}\leq\Phi^*.

Formal verification. A second Lean 4 development, based on Mathlib, formalizes Lemma 4, Theorems 5 and 6, Corollary 7 and Proposition 8 for every finite strict partial order and every rank 1≤i≤n1\leq i\leq n, with C(P)C(P) defined through total orders extending PP as above. Its decision trees may compare any two of the original elements, even when their order is known; a tree is correct if it returns the ii-th smallest element for every total order extending PP, and comparisons are counted along the path of each such input. Theorem 5 is proved for the number of leaves and as Φ∗(P)≤2d\Phi^*(P)\leq2^d for every correct tree making at most dd comparisons on every input, with Φ∗\Phi^* computed in the integers. The proofs use only the standard axioms and replay in leanc​hecker; the trusted base now includes the Mathlib definitions used in the statements. The evaluation and Remark 9 rest on computation and are not formalized.

Evaluation. At the empty order, ⌈log⁡2Φ∗⌉\lceil\log_2 \Phi^*\rceil improves the one-sided bound by one comparison for fifteen pairs (n,i)(n,i) with n≤16n \le16 and i≤⌈n/2⌉i \le\lceil n/2\rceil, but gives only 23 for (16,8)(16,8); it does not reproduce the lower bound 28. The local inequality of Theorem 5 holds on all 149,598 cases with at most 7 elements (isomorphism classes, unsolved ranks, all incomparable pairs). An independent exhaustive check over all partial orders with at most 9 elements, up to isomorphism, found no violation of Theorems 5 and 6 against exact values. On a corpus of 1,663,508 exactly solved reduced problems with at most 12 elements, gathered by our exact solver during its searches, the average gap to the exact value is 2.62 for ⌈log⁡2∣C∣⌉\lceil\log_2 |C|\rceil and 1.13 for LB, and LB is exact on 10% of them.

Remark 9 (A limit of leaf counting). No lower bound on the number of leaves of every correct tree can prove V8(16)≥29V_8(16) \ge29 by taking its ceiling logarithm. The 252-function 29-comparison certificate unfolds into a tree with 248,381,440 syntactic leaves, fewer than 2282^{28}, computed by two independent counts. Any bound valid for all correct trees is at most this number, so its ceiling logarithm is at most 28. A proof of 29, if true, must use depth or path information.

How the algorithms were found

The search is not part of the proofs; it only had to produce certificates. Three changes to the forward search of [5] made this practical.

Fixed budget, first success. That search computes optima by trying budgets upward from a lower bound and keeps looking for better comparisons after finding one that works. We instead fix a budget kk and accept the first comparison whose two outcomes are both solvable within k−1k - 1. One or two comparisons of slack make construction much easier: for (14,7)(14,7), with optimum 25, the time fell from 659 s at the optimum to 119 s and 17.6 s at one and two above it.

Information-greedy ordering. Candidate comparisons are tried in increasing order of the larger compatible-solution count of their two outcomes. On two benchmarks this reduced the searched nodes by factors of about 20 and 100, and at the optimum the time for (14,7)(14,7) fell from 659 s to 3.0 s. With this ordering, budget 29 for (16,8)(16,8) was solved in about two minutes and budget 29 for (16,7)(16,7) in 17 minutes, but budget 28 for (16,7)(16,7) remained unsolved after about 50 minutes. The bound LB of Corollary 7 serves as the pruning rule.

Proof-number search. Better ordering alone did not reach the tightest budgets. Even an ordering by Φ∗\Phi^*, which put an optimal comparison first in about 96% of exactly solved problems with 7 to 10 elements, did not find a 26-comparison algorithm for (15,7)(15,7) by depth-first search. This suggested that the difficulty lay in revising early choices rather than in making them: depth-first search can spend very long refuting one early wrong choice before trying another. Construction is an AND/OR problem: one comparison must succeed at each state, and both of its outcomes must succeed. Depth-first proof-number search (df-pn) [1, 13, 11] redirects effort to cheaper alternatives before a choice is fully refuted. We initialize unexplored nodes from a cost predictor fitted to the corpus of solved small problems, shifted pessimistically, which mattered by factors of 1010–100100. Table 4 compares the two searches; df-pn found the 28-comparison algorithm for (16,7)(16,7) in five seconds.

instancedf-pndepth-firstfunctions
(14,7)(14, 7) at 250.55 s3.0 s412
(15,7)(15, 7) at 2679 snot found (35 min)1614
(16,7)(16, 7) at 285.0 snot found (50 min)329
(16,8)(16, 8) at 29320 s2 min2937

Table 4. Time to construct an algorithm at the stated budget (single thread).

For 17 elements we widened the solver’s representation to at most 19 elements; it reproduces earlier certificates byte for byte. Starting from the upper bounds of [9], df-pn reached the bounds of Theorem 3 within 89 s to 63 min per rank (Table 3); for rank 5 this meets the lower bound.

BoundFunctionsSearch timeSHA-256 prefix
V7(16)≤28V_{7}(16) \le283295 seb8f064c12bb
V8(16)≤29V_{8}(16) \le2929375 min2e9615ae1d9b
V5(17)≤27V_{5}(17) \le27146103 s34e26f201b68
V6(17)≤29V_{6}(17) \le2926689 sae6d6b42e1c4
V7(17)≤30V_{7}(17) \le309778 min33718071f64a
V8(17)≤31V_{8}(17) \le31107719 min5925b96967a8
V9(17)≤31V_{9}(17) \le31149363 min9ce649f22b2d

Table 3. The certificates used in the Lean proofs, found by proof-number search (single thread, AMD Ryzen 7 5800X). Further certificates for the 16-element bounds, with 365 and 252 functions, are archived.

For V8(16)V_8(16) at 28, two df-pn runs of 6,600 s and a six-hour portfolio ended undecided. Refutations one below the optimum grew by factors of about 100–300 per added element on the instances we measured, so an exhaustive refutation at 16 elements was out of reach on our desktop.

Conclusion and open problems

The previous best upper bounds for these entries came from a search restricted to a few heuristically chosen comparisons per node [9]; the exhaustive search of [5] aims at optimal values, which were out of reach for them. Our results indicate that much of the remaining gap was a matter of search strategy. Asking only for some algorithm within a fixed budget avoids computing optimal values of subproblems, and ordering comparisons by the remaining uncertainty makes good choices likely. Near the optimum this was not enough: the difficulty appeared to lie in revising early choices, and proof-number search, which can turn to an alternative before the current choice is fully refuted, overcame it. On some instances, such as the median of 16 at budget 29, depth-first search was faster, so the two strategies are complementary. Since every bound is checked independently of the search, none of these heuristics needs to be correct for the results to hold.

The same experience shows where the difficulty now lies. Constructing an algorithm became cheap, but proving that none exists within a budget remained expensive: refutations one below the optimum grew by factors of about 100–300 per added element in our measurements, and the 28-comparison question for the median of 16 stayed undecided. For the open entries, progress depends mainly on lower bounds.

Open problems. Is V8(16)V_8(16) equal to 28 or 29? A 28-comparison certificate would settle it constructively; a proof of 29 must exclude all such algorithms and, by Remark 9, needs more than a total leaf count. An analytic proof of V7(16)≥28V_7(16) \ge28 would remove the dependence on a large computation. The gaps for n=17n = 17 at ranks 6–9 remain open. Finally, can the runner-up opening be extended into a family of good selection algorithms, for example for central ranks of 2k2^k elements?

Data availability

Code, certificates, and Lean proofs are archived on Zenodo as release v1.0.0 [16]. The development repository is available at https://github.com/JCremerr/selection-7-of-16.

Use of AI

This work was inspired by recent AI-assisted results in combinatorics [4] and was carried out with AI coding assistants. The author chose the problem, directed the searches, and developed the text with the assistants in successive revisions. The assistants implemented the software and produced first drafts of the proofs. The author is responsible for the content.

Acknowledgments

We thank J. Dörrer, K. Gendle, J. Betz, J. von Smercek, A. Steding and F. Stober for publishing their search code and optimal algorithms.

References

  1. [1]L. V. Allis, M. van der Meulen, and H. J. van den Herik. Proof-number search. Artificial Intelligence, 66(1):91–124, 1994.
  2. [2]M. Blum, R. W. Floyd, V. Pratt, R. L. Rivest, and R. E. Tarjan. Time bounds for selection. Journal of Computer and System Sciences, 7(4):448–461, 1973.DOI
  3. [3]S. W. Bent and J. W. John. Finding the median requires 2n comparisons. In Proc. 17th ACM Symposium on Theory of Computing, pages 213–216, 1985.DOI
  4. [4]F. Cremer. Lower bounds for Ramsey numbers: R(6, 8) ≥ 135 and R(8, 10) ≥ 345. arXiv:2610.12122, 2026.arxiv.org/abs/2610.12122
  5. [5]J. Dörrer, K. Gendle, J. Betz, J. von Smercek, A. Steding, and F. Stober. Exact lower bounds for the number of comparisons in selection. In 23rd International Symposium on Experimental Algorithms (SEA 2025), LIPICs 338, pages 16:1–16:15, 2025. doi:10.4230/LIPICs.SEA.2025.16.
  6. [6]D. Dor and U. Zwick. Selecting the median. SIAM Journal on Computing, 28(5):1722–1758, 1999.
  7. [7]D. Dor and U. Zwick. Median selection requires (2 + ε)n comparisons. SIAM Journal on Discrete Mathematics, 14(3):312–325, 2001.
  8. [8]F. Fussenegger and H. N. Gabow. A counting approach to lower bounds for selection problems. Journal of the ACM, 26(2):227–238, 1979.DOI
  9. [9]W. Gasarch, W. Kelly, and W. Pugh. Finding the ith largest of n for small i, n. SIGACT News, 27(2):88–96, 1996. doi:10.1145/235767.235772.
  10. [10]A. Hadian and M. Sobel. Selecting the t-th largest using binary errorless comparisons. Technical report, University of Minnesota, 1969.
  11. [11]A. Kishimoto, M. H. M. Winands, M. Müller, and J.-T. Saito. Game-tree search using proof numbers: The first twenty years. ICGA Journal, 35(3):131–156, 2012.DOI
  12. [12]D. E. Knuth. The Art of Computer Programming, Vol. 3: Sorting and Searching. Addison-Wesley, 2nd edition, 1998.
  13. [13]A. Nagai. Df-pn Algorithm for Searching AND/OR Trees and Its Applications. PhD thesis, University of Tokyo, 2002.
  14. [14]K. Oksanen. Selecting the ith largest of n elements. https://www.cs.hut.fi/~cessu/selection/, 2002.
  15. [15]K. Oksanen. Searching for selection algorithms. Electronic Notes in Discrete Mathematics, 27:77, 2006.DOI
  16. [16]J. Cremer. Selecting the 7th Smallest of 16 Elements Takes Exactly 28 Comparisons: code, certificates and Lean proofs. Version v1.0.0. Zenodo, 2026. doi:10.5281/zenodo.23346948.DOI

Paper details

vlnc:W_h4dzpnqp
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

AI coding assistants

View statement
Looking for related papers…
Contents