Graph Theory37 sections · 1633 units
Open in Course

Euler Tour + RMQ - Complexity

(Time and space analysis)

Euler tour construction: O(n)O(n) time because you visit each edge exactly twice (once down, once up). Sparse table construction: O(nlogn)O(n \log n) time and space because the table has nn rows and logn\log n columns, and each cell takes O(1)O(1) to fill. Query: O(1)O(1) time because you look up two precomputed values in the sparse table.

Total: O(nlogn)O(n \log n) preprocessing, O(1)O(1) per query, O(nlogn)O(n \log n) space. For qq queries, total time is O(nlogn+q)O(n \log n + q). Compare this to binary lifting: O(nlogn+qlogn)O(n \log n + q \log n). The difference matters when qq is large.