Graph Theory37 sections · 1633 units
Open in Course

Building the Table

(Column by column)

Build the table column by column. First, fill column 00 (parents). Then fill column 11 using column 00. Then fill column 22 using column 11. And so on. For each column jj from 11 to logn\log n, and for each node vv, set:

up[v][j] = up[up[v][j-1]][j-1]

Time: O(nlogn)O(n \log n), because you fill nlognn \log n entries, each in O(1)O(1) time. Space: O(nlogn)O(n \log n) for the table. For n=200,000n = 200,000, the table has about 3.43.4 million entries.