Mo’s Algorithm
Mo’s Algorithm
Introduction to Mo’s Algorithm
Mo’s Algorithm technique that depends on the Square Root Decomposition Algorithm. It is an efficient for answering range query problems, especially when the queries involve a static array (no updates) and can be processed offline. This algorithm is particularly useful for problems where processing queries is expensive.
Concept
Mo’s Algorithm optimizes range queries by grouping them into blocks and sorting the blocks to minimize the cost of moving from one range to the next. This approach significantly reduces the number of computations needed to process all queries.
SQRT Decomposition Limitation
To understand what Mo’s algorithm does best, we need to remember how queries were processed in normal SQRT decomposition. This can be summarized in:
- For each query we find all the blocks containing some part of . There can be at most such blocks.

