Graph Theory37 sections · 1633 units
Open in Course

Query Processing

(Decomposing k into powers)

To find fk(x)f^k(x), write kk in binary. For each bit that is 11, make the corresponding jump. This decomposes kk into a sum of powers of 22. Start at xx. For each bit position ii from high to low, if bit ii is set in kk, update x=jump[i][x]x = \text{jump}[i][x].

Process all set bits. After processing all bits, you are at fk(x)f^k(x). This takes O(logk)O(\log k) time because kk has at most logk\log k bits. Each bit is a constant-time lookup.