Range Majority in Constant Time and Linear Space

Given an array A of size n, we consider the problem of answering range majority queries: given a query range [i..j] where 1 ≤ i ≤ j ≤ n, return the majority element of the subarray A[i..j] if it exists. We describe a linear space data structure that answers range majority queries in constant time. We further generalize this problem by defining range a-majority queries: given a query range [i..j], return all the elements in the subarray A[i..j] with frequency greater than α(j-i+1). We prove an upper bound on the number of α-majorities that can exist in a subarray, assuming that query ranges are restricted to be larger than a given threshold. Using this upper bound, we generalize our range majority data structure to answer range a-majority queries in O(1/α) time using O(n lg(1/α + 1)) space, for any fixed α ∈ (0, 1). This result is interesting since other similar range query problems based on frequency have nearly logarithmic lower bounds on query time when restricted to linear space.

[1]  Steven Skiena,et al.  The Algorithm Design Manual , 2020, Texts in Computer Science.

[2]  Holger Petersen Improved Bounds for Range Mode and Range Median Queries , 2008, SOFSEM.

[3]  Marek Karpinski,et al.  Searching for Frequent Colors in Rectangles , 2008, CCCG.

[4]  Timothy M. Chan,et al.  Linear-Space Data Structures for Range Mode Query in Arrays , 2011, Theory of Computing Systems.

[5]  Graham Cormode,et al.  An improved data stream summary: the count-min sketch and its applications , 2004, J. Algorithms.

[6]  Martin Aigner Variants of the majority problem , 2004, Discret. Appl. Math..

[7]  Holger Petersen,et al.  Range mode and range median queries in constant time and sub-quadratic space , 2009, Inf. Process. Lett..

[8]  J. Ian Munro,et al.  Sorting and Searching in Multisets , 1976, SIAM J. Comput..

[9]  Michiel H. M. Smid,et al.  Range Mode and Range Median Queries on Lists and Trees , 2003, Nord. J. Comput..

[10]  David P. Dobkin,et al.  Determining the Mode , 1980, Theor. Comput. Sci..

[11]  Allan Grønlund Jørgensen,et al.  Cell Probe Lower Bounds and Approximations for Range Mode , 2010, ICALP.

[12]  Jayadev Misra,et al.  Finding Repeated Elements , 1982, Sci. Comput. Program..

[13]  Prosenjit Bose,et al.  Approximate Range Mode and Range Median Queries , 2005, STACS.

[14]  Roberto Grossi,et al.  High-order entropy-compressed text indexes , 2003, SODA '03.

[15]  Robert S. Boyer,et al.  MJRTY: A Fast Majority Vote Algorithm , 1991, Automated Reasoning: Essays in Honor of Woody Bledsoe.

[16]  Edward M. Reingold,et al.  Determining plurality , 2008, TALG.