Centroid Decomposition

Some distance problems resist DFS and DP. Centroid decomposition gives divide-and-conquer on trees.

55 lessons
160 min

Lessons

1. Intro

(Divide and conquer on trees)

3m

2. Why Centroid Decomposition?

(When DFS and DP fail)

3m

3. What is a Centroid?

(The balance point of a tree)

3m

4. Centroid Existence Proof

(Every tree has one)

3m

5. Finding the Centroid

(Walk toward heavy subtrees)

3m

6. Example: Finding a Centroid

(Walking through the process)

3m

7. Centroid Properties

Why it works for divide-and...

3m

8. Quiz: Centroid Properties

Knowledge check

2m1 problems

9. The Centroid Decomposition Tree

Recursive structure of cent...

3m

10. Why Depth is O(log n)

(Each level halves the size)

3m

11. Quiz: Decomposition Tree Depth

Knowledge check

2m1 problems

12. Building the Decomposition Tree

(Recursive centroid finding)

3m

13. Decomposition Tree vs Original Tree

(Two different structures)

3m

14. Paths Through Centroids

core idea for path problems

3m

15. Divide and Conquer on Trees

(The general pattern)

3m

16. Problem - Finding a Centroid

(CSES 2079)

3m1 problems

17. Read Statement

(Problem link)

3m1 problems

18. Core idea 1 - Subtree Sizes

(Compute sizes with DFS)

3m

19. Core idea 2 - Walk to Heavy Subtree

(Move toward balance)

3m

20. Algorithm - Find Centroid

(Two-phase approach)

3m

21. Finding a Centroid - Implementation

(Complete solution)

3m

22. Walkthrough

(Tracing the algorithm)

3m

23. Lessons Learned

(summary)

3m

24. Quiz: Finding the Centroid

Knowledge check

2m1 problems

25. Problem - Fixed-Length Paths I

(CSES 2080)

3m1 problems

26. Read Statement

(Problem link)

3m1 problems

27. Core idea 1 - Paths Through Centroid

(Divide by centroid)

3m

28. Core idea 2 - Combining Subtree Paths

Count distances from centroid

3m

29. Core idea 3 - Subtract Same-Subtree Paths

Avoid counting paths within...

3m

30. Algorithm - Count Paths Through Centroid

(The recursive structure)

3m

31. Fixed-Length Paths I - Implementation

(Complete solution)

3m1 problems

32. Walkthrough

(Example trace)

3m

33. Lessons Learned

(Path counting with centroids)

3m

34. Quiz: Counting Paths Through Centroid

Knowledge check

2m1 problems

35. Problem - Fixed-Length Paths II

(CSES 2081)

3m1 problems

36. Read Statement

(Problem link)

3m1 problems

37. Core idea - Count Range Instead of Exact

(Modify the counting step)

3m

38. Algorithm - Count Paths in Range

(Range query on distances)

3m

39. Fixed-Length Paths II - Implementation

(Range counting with map)

3m1 problems

40. Walkthrough

(Example with range)

3m

41. Lessons Learned

(Range queries on paths)

3m

42. Distance Queries with Centroid Decomposition

Preprocessing for fast queries

3m

43. When to Use Centroid Decomposition

(Problem recognition)

3m

44. Quiz: When to Apply Centroid Decomposition

Knowledge check

2m1 problems

45. Centroid Decomposition vs Other Techniques

(Choosing the right tool)

3m

46. Implementation Tips

(Avoiding common mistakes)

3m

47. Complexity Analysis

(Why it's O(n log n))

3m

48. Space Complexity

(Memory usage)

3m

49. Variations and Extensions

(Beyond basic path counting)

3m

50. Debugging Centroid Decomposition

(Common errors and fixes)

3m

51. Practice Problems

(Build your skills)

3m

52. Check Your Understanding

(Centroid definition)

3m

53. Check Your Understanding

(Decomposition depth)

3m

54. Check Your Understanding

(Path counting logic)

3m

55. Section Recap

(What you learned)

3m

Practice Problems

3.
Digit TreeCodeforceshard
4.
RaceCodeforceshard

Ready to start learning?

Access all 55 lessons with interactive content and progress tracking.