Graph Theory37 sections · 1633 units
Open in Course

Planets Queries I - Walkthrough

(Example execution)

Graph: f(1)=2,f(2)=3,f(3)=4,f(4)=1f(1) = 2, f(2) = 3, f(3) = 4, f(4) = 1. This forms a cycle of length 44. Query: start at 11, go 77 steps. You need to find where you land. Jump table: jump[0]=[2,3,4,1]\text{jump}[0] = [2,3,4,1], jump[1]=[3,4,1,2]\text{jump}[1] = [3,4,1,2], jump[2]=[1,2,3,4]\text{jump}[2] = [1,2,3,4].

Each row is built from the previous row by composing the function. k=7=4+2+1k = 7 = 4 + 2 + 1 in binary: 111111. Start at 11. Jump 44: reach 11. Jump 22: reach 33. Jump 11: reach 44. Answer: 44. The binary decomposition makes it efficient.