Range Queries

There are ample scenarios in daily software routines where we want to execute a query over a range. Unlike executing a query simply over two elements which take O(1) time, query over a range of n elements in general will take O(n) time. High frequency of such queries could hamper the performance of the codebase. There are techniques which more or less involve pre-computation that can help us execute a range query over n elements in O(1) or O(log n) time. Obviously there could be high time complexity involved with updates over these pre-computed structures.

On a high level, we can club such scenarios into four broad categories: