Data Structures19 sections · 729 units
Open in Course

Application: Mode in Range

Most frequent element

Find the most frequent element in A[l..r]A[l..r].

Wavelet trees don't directly support this, but can help: Approach: Candidate testing Use other techniques (random sampling, heavy hitters) to find candidates, then verify with wavelet tree frequency queries. Approach: Small alphabet If σ\sigma is small, check frequency of each value in O(σlogσ)O(\sigma \log \sigma).

Approach: Mo's algorithm + frequency tracking For offline queries, Mo's algorithm with frequency map works in O((n+q)n)O((n + q) \sqrt{n}).

Mode queries are harder than quantile queries. No known O(logn)O(\log n) solution exists for arbitrary ranges.