Blocks Where Trees Fail

Why reach for n\sqrt{n} decomposition when a segment tree exists and is asymptotically better?

A

Because blocking has better cache locality and the asymptotics on real hardware follow the memory hierarchy: a block is one contiguous scan. You gain an O(log⁡n)O(\log n) effective bound for that locality.

B

Because the aggregate need not be decomposable and the update need not have a composable lazy tag: a block can simply be rebuilt or brute-forced. You pay O(n)O(\sqrt{n}) per operation for that generality.

C

Because O(n)O(\sqrt{n}) beats O(log⁡n)O(\log n) below roughly n=106n = 10^6 once constants are counted: a block scan is one flat loop with no pointer chasing. You gain real speed up to that size.

D

Because a segment tree cannot apply an update to a whole range at all, only to a point: a block can absorb the range and defer it. You pay O(n)O(\sqrt{n}) per operation for that generality.