Graph Theory37 sections · 1633 units
Open in Course

Preprocessing Table

(Computing jump pointers)

Create a table where jump[i][x]\text{jump}[i][x] stores f2i(x)f^{2^i}(x). Base case: jump[0][x]=f(x)\text{jump}[0][x] = f(x). This is only one step. For i1i \geq 1: jump[i][x]=jump[i1][jump[i1][x]]\text{jump}[i][x] = \text{jump}[i-1][\text{jump}[i-1][x]]. Jumping 2i2^i steps is jumping 2i12^{i-1} steps twice.

Build the table bottom-up. Store up to i=log2ni = \lfloor \log_2 n \rfloor since you cannot jump more than nn steps without repeating in a cycle. This bounds the table size.