Binary Lifting

Find ancestors by jumping one step at a time? That's O(n). Binary lifting makes it O(log n).

50 lessons
144 min

Lessons

1. Intro

(The goal)

3m

2. The k-th Ancestor Problem

(Find ancestor k steps up)

3m

3. Naive Approach

(Jump one step at a time)

3m

4. Binary Representation Core Idea

(Any number as sum of powers)

3m

5. Sparse Table Idea

(Store power-of-2 ancestors)

3m

6. Table Dimensions

(How many columns needed)

3m

7. Base Case - First Column

(Direct parents)

3m

8. Recurrence Relation

Build from previous

3m

9. Recurrence Example

(How $up[v][2]$ is computed)

3m

10. Quiz: Sparse Table Construction

Knowledge check

2m1 problems

11. Building the Table

(Column by column)

3m

12. Building Code

(Pseudocode for preprocessing)

3m

13. Answering Queries

(Decompose k into powers)

3m

14. Query Pseudocode

(Jump by set bits)

3m

15. Query Example

(Finding 13th ancestor)

3m

16. Quiz: Query Decomposition

Knowledge check

2m1 problems

17. Complexity Summary

(Preprocessing and queries)

3m

18. Problem - Company Queries I

(CSES 1687 - k-th ancestor)

3m1 problems

19. Core Idea - Tree Structure

(Input is a tree)

3m

20. Core Idea - Handling Invalid Queries

(When k exceeds depth)

3m

21. Algorithm

Preprocess then query

3m

22. Company Queries I - Implementation

Binary lifting code

3m1 problems

23. Walkthrough

(Sample input trace)

3m

24. Lessons Learned

(What you practiced)

3m

25. Quiz: K-th Ancestor Edge Cases

Knowledge check

2m1 problems

26. Extension - LCA

Finding LCA

3m

27. Problem - Company Queries II

(CSES 1688 - LCA)

3m1 problems

28. Core Idea - Same Depth First

(Bring nodes to same level)

3m

29. Core Idea - Binary Search for LCA

(Jump both simultaneously)

3m

30. Why This Works

(Jump as far as possible)

3m

31. Algorithm

(LCA with binary lifting)

3m

32. Company Queries II - Implementation

(Pseudocode for LCA)

3m1 problems

33. Walkthrough

(Sample LCA trace)

3m

34. Walkthrough - Different Subtrees

(Nodes in separate branches)

3m

35. Lessons Learned

(What you practiced)

3m

36. Quiz: LCA via Binary Lifting

Knowledge check

2m1 problems

37. Problem - Kth Ancestor of a Tree Node

(LeetCode 1483)

3m1 problems

38. Core Idea - Constructor Preprocessing

(Build table once)

3m

39. Core Idea - Query Method

(Return -1 if out of bounds)

3m

40. Algorithm

(Class-based binary lifting)

3m

41. Kth Ancestor - Implementation

(Pseudocode for class)

3m1 problems

42. Walkthrough

(Sample queries)

3m

43. Lessons Learned

(What you practiced)

3m

44. Quiz: Time and Space Tradeoffs

Knowledge check

2m1 problems

45. Applications Beyond Ancestors

(Where binary lifting is used)

3m

46. Space Improvement Note

(Reducing memory usage)

3m

47. Comparison to Naive Approach

(Why binary lifting wins)

3m

48. Quiz: Binary Lifting Recurrence

Knowledge check

2m1 problems

49. Next Section Teaser

(More LCA techniques)

3m

50. Section Recap

(What you learned)

3m

Practice Problems

2.
3.
4.
Fools and RoadsCodeforceshard

Ready to start learning?

Access all 50 lessons with interactive content and progress tracking.