Graph Theory37 sections · 1633 units
Open in Course

Binary Representation Core Idea

(Any number as sum of powers)

Here is the core idea: any number kk can be written as a sum of powers of 22. For example, 13=8+4+1=23+22+2013 = 8 + 4 + 1 = 2^3 + 2^2 + 2^0. To jump up 1313 steps, you could jump 88 steps, then 44, then 11. That is only 33 jumps instead of 1313. This works because every number has at most logk\log k bits in its binary representation.

So you need at most logk\log k jumps. For kk up to 10510^5, that is at most 1717 jumps per query.