Graph Theory37 sections · 1633 units
Open in Course

Complexity Summary

(Preprocessing and queries)

Preprocessing: O(nlogn)O(n \log n) time, O(nlogn)O(n \log n) space. You build the sparse table once. Queries: O(logk)O(\log k) per query, where kk is the jump distance. In the worst case, k=nk = n, so queries take O(logn)O(\log n). If you have qq queries, total time is O(nlogn+qlogn)O(n \log n + q \log n). For n=100,000n = 100,000 and q=1,000,000q = 1,000,000, that is under 2020 million operations.

This is fast enough for any competitive programming time limit.