Practice Discrete Math

Algorithms / Binary Lifting

Least You Need to Know: Binary Lifting, Power-of-Two Jumps, and Ancestor Queries

Binary lifting preprocesses jump pointers so ancestor movement can be decomposed into **powers of two**. The main trick is the same as binary representation: any jump length can be written as a sum of power-of-two jumps.

جو کم از کم جاننا ضروری ہے

اہم علامتیں

up[v][j] the `2^j`-th ancestor of node `v`
k number of levels to climb
set bit a power of two present in the binary expansion of `k`

مختصر حل شدہ مثال

  • If `k = 13`, write `13 = 8 + 4 + 1`.
  • From node `v`, jump to the `2^3`-ancestor, then the `2^2`-ancestor of that node, then the `2^0`-ancestor.
  • Only three table lookups are needed instead of climbing one edge at a time.
  • The same idea helps equalize depths before finishing an LCA query.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Binary Search Invariants and Boundary Updates.

Least You Need to Know: Binary Search Invariants and Boundary Updates

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں