Exact (n + 2) Comparison Complexity for the N-Repeated Element Problem
Andrew Au
TL;DR
The paper determines the exact worst-case number of equality comparisons needed to identify the element appearing $n$ times in a $2n$-element array with $n+1$ distinct values, under $O(1)$ extra space. It presents a simple deterministic algorithm achieving exactly $n+2$ comparisons and proves a matching lower bound via an adversary argument built on the inequality graph $I$ and its complement $P$, using a pillar-matching construction and edge-flip reconfiguration to maintain ambiguity up to the $(n+1)$th comparison. The bound is shown to be tight because, after $n$ comparisons, the adversary can maintain two disjoint $n$-cliques in $P$, and only at the $(n+2)$nd comparison does this strategy fail. The work illustrates how strictly equality-based queries yield precise lower bounds and clarifies why incorporating magnitude comparisons could collapse the bound through transitive inferences.
Abstract
This paper establishes the exact comparison complexity of finding an element repeated $n$ times in a $2n$-element array containing $n+1$ distinct values, under the equality-comparison model with $O(1)$ extra space. We present a simple deterministic algorithm performing exactly $n+2$ comparisons and prove this bound tight: any correct algorithm requires at least $n+2$ comparisons in the worst case. The lower bound follows from an adversary argument using graph-theoretic structure. Equality queries build an inequality graph $I$; its complement $P$ (potential-equalities) must contain either two disjoint $n$-cliques or one $(n+1)$-clique to maintain ambiguity. We show these structures persist up through $n+1$ comparisons via a "pillar matching" construction and edge-flip reconfiguration, but fail at $n+2$. This result provides a concrete, self-contained demonstration of exact lower-bound techniques, bridging toy problems with nontrivial combinatorial reasoning.
