Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Binary Representation

(Why powers of 2 work)

Any number kk can be written as a sum of distinct powers of 22. That is what binary representation means. For example, 13=8+4+1=23+22+2013 = 8 + 4 + 1 = 2^3 + 2^2 + 2^0. If k=13=8+4+1k = 13 = 8 + 4 + 1, you jump 88 steps, then 44, then 11. Each jump is precomputed.

You combine precomputed results to get the final answer. This decomposition is unique and uses at most logk\log k powers, giving you the logarithmic query time. Binary representation is what makes it work.