Graph Theory37 sections · 1633 units
Open in Course

Recurrence Example

(How $up[v][2]$ is computed)

Say you want up[v][2], the 44th ancestor of vv. First, jump 22 steps: up[v][1] is the grandparent. Then jump another 22 steps from there: up[up[v][1]][1]. You have jumped 2+2=42 + 2 = 4 steps total. So:

up[v][2] = up[up[v][1]][1]

This pattern holds for all jj. Every column depends only on the previous column, so you compute columns in order from 00 to log⁡n\log n. Each entry is filled in O(1)O(1) time.