The Erdős-Ginzburg-Ziv theorem states that every sequence of 2n - 1 integers contains a subsequence of length n whose sum is divisible by n. Choi, Kang, and Lim gave a simple deterministic O(n log n) algorithm for finding such a subsequence, and Leung recently improved this to O(n log log log n). We give a deterministic linear-time algorithm. The core is a linear-time algorithm for the following prime target subset-sum problem: given p - 1 nonzero residues in Z_p and a target residue, find a subset with the prescribed sum. Our algorithm maintains a compact arithmetic-progression representation of reachable sums. When two progressions intersect, a bounded Frobenius interval in their sum allows them to be merged into one longer progression, with enough growth to pay for the update. When the representation either contains a full progression or covers all nonzero residues, the target residue is recovered constructively. The standard multiplicative reduction then extends the prime algorithm to arbitrary moduli.
翻译:Erdős–Ginzburg–Ziv 定理指出,任意由 2n - 1 个整数构成的序列中,必存在一个长度为 n 的子序列,其和能被 n 整除。Choi、Kang 和 Lim 给出了一个简单的确定性 O(n log n) 算法来寻找这样的子序列,最近 Leung 将其改进为 O(n log log log n)。本文给出一个确定性线性时间算法。其核心是针对素数目标子集和问题的线性时间算法:给定 Z_p 中的 p - 1 个非零剩余和一个目标剩余,求一个子集其和为指定值。我们的算法维护可达和的一种紧凑算术级数表示。当两个级数相交时,它们和中的一个有界 Frobenius 区间允许它们合并为一个更长的级数,且增长量足以支付更新代价。当表示要么包含一个完整级数,要么覆盖所有非零剩余时,可以构造性地恢复目标剩余。最后,标准的乘法归约将该素数算法推广到任意模数。