Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Cycle Position Index

(Tracking location in loop)

Assign each cycle node an index from 00 to λ1\lambda - 1 where λ\lambda is cycle length. Start from any cycle node and assign indices in order. Distance from cycle node ii to cycle node jj is (ji)modλ(j - i) \mod \lambda.

This works because the cycle wraps around. The modulo handles the wraparound. Storing indices makes distance computation a single modulo operation instead of simulation. This is much faster for large cycles.