Not Always Root N

Mo's algorithm over an array of nn elements with mm queries. What block size, and what bound?

A

S=n/log⁡mS = n/\log m, giving O(nlog⁡m)O(n \log m). Only when m=Θ(n)m = \Theta(n) does that collapse to the log⁡n\log n block and the O(nlog⁡n)O(n \log n) everyone quotes.

B

S=n/mS = n/\sqrt{m}, giving O(nm)O(n\sqrt{m}). Only when m=Θ(n)m = \Theta(n) does that collapse to the n\sqrt{n} block and the O(nn)O(n\sqrt{n}) everyone quotes.

C

S=nS = \sqrt{n}, giving O(nn)O(n\sqrt{n}) for every mm. The block never depends on the query count, since only the right pointer's O(n2/S)O(n^2/S) term matters.

D

S=mS = \sqrt{m}, giving O(mn)O(m\sqrt{n}). Only when m=Θ(n)m = \Theta(n) does that collapse to the n\sqrt{n} block and the O(nn)O(n\sqrt{n}) everyone quotes.