AlgoScope

Sparse Table Build and Query

k = floor(log2(len)). The answer is min of the windows starting at l and ending at r, overlap harmless.

Range queries, algorithm, advanced
Use row 2^2.012345672^02^12^22^3524713682241136211111
Use row 2^2.012345672^02^12^22^3524713682241136211111

Sparse Table: Query with overlapping windows

Decision, step 2 of 4

5 values fit a window of length 4 = 2^2 and not of 8, so k = 2: use row 2^2.

How sparse table works

Cost

Best
O(1)
Average
O(1)
Worst
O(1)
Space
O(n log n)

O(n log n) build.

Taught by the same lesson

Sparse Table covers these too, in the same run.