அல்கோரிதம்tree lifting

Tree lifting — binary lifting

TT
Testlaa Team
May 14, 20261 min read

2^k ancestor jumps — LCA/path queries.

Try this in Python

LOG = 3  # toy
# up[v][k] would store 2^k-th ancestor; build omitted for brevity
up = [[-1, -1, -1] for _ in range(5)]
print("Store up[v][k] for k in 0..LOG-1; answer queries by jumping powers of two")

Key takeaways

  • Rooted tree + parent.
  • Dynamic — link-cut.
  • LOG = bit length n.

Tags:

Tree structuresPythonமாணவர்கள்