Given an array A of size n, we consider the problem of answering range majority queries: given a query range where , return the majority element of the subarray 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 α-majority queries: given a query range , return all the elements in the subarray with frequency greater than . 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 α-majority queries in time using space, for any fixed . 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.
This research was supported through NSERC of Canada and the Canada Research Chairs Program. A preliminary version of these results appeared at the 38th International Colloquium on Automata, Languages and Programming [12].