Euler Tour Technique

Flatten trees into arrays. Subtrees become ranges. Query and update subtrees with range structures.

51 lessons
147 min

Lessons

1. Intro

(Converting trees to arrays)

3m

2. What is an Euler Tour

(DFS traversal order)

3m

3. Entry and Exit Times

(tin and tout arrays)

3m

4. Subtrees as Ranges

(Why this works)

3m

5. Flattening the Tree

(Building the array)

3m

6. Basic Implementation

(Computing tin and tout)

3m

7. Example Tree

(Computing times step by step)

3m

8. Quiz: Entry and Exit Times

Knowledge check

2m1 problems

9. Check Your Understanding

(Entry/exit time properties)

3m

10. Problem - Subtree Queries

(CSES 1137)

3m1 problems

11. Core Idea - Subtree to Range

(The key observation)

3m

12. Core Idea - Which Times to Use

(Entry times only)

3m

13. Algorithm

(Euler tour plus segment tree)

3m

14. Subtree Queries - Implementation

(Code and submit)

3m1 problems

15. Subtree Queries - Walkthrough

(Example execution)

3m

16. Lessons Learned

(summary)

3m

17. Quiz: Subtree as Range

Knowledge check

2m1 problems

18. Euler Tour Variants

(Different approaches)

3m

19. Entry-Only Variant

(Just tin values)

3m

20. Entry-Exit Variant

(tin and tout pairs)

3m

21. Full Tour Variant

(Complete node sequence)

3m

22. Quiz: Euler Tour Variants

Knowledge check

2m1 problems

23. Check Your Understanding

(Variant selection)

3m

24. Problem - Path Queries

(CSES 1138)

3m1 problems

25. Core Idea - Path as Prefix

(DFS order property)

3m

26. Core Idea - Prefix Sum Trick

(Converting to range query)

3m

27. Algorithm

(Modified Euler tour)

3m

28. Path Queries - Implementation

(BIT for prefix sums)

3m1 problems

29. Path Queries - Walkthrough

(Example execution)

3m

30. Lessons Learned

Adding and subtracting

3m

31. Quiz: Path Query Updates

Knowledge check

2m1 problems

32. Combining with Segment Trees

(Beyond sums)

3m

33. BIT as Lighter Alternative

(When to use Fenwick tree)

3m

34. Space Complexity

(Memory usage)

3m

35. Update Types

(Point vs range updates)

3m

36. Query Types

(What you can ask)

3m

37. Ancestor Check

(Fast relationship test)

3m

38. Rerooting Limitation

(Fixed root only)

3m

39. Check Your Understanding

(Complexity analysis)

3m

40. DFS Order Matters

(Consistent traversal)

3m

41. Quiz: Ancestor Check

Knowledge check

2m1 problems

42. Connection to Heavy-Light Decomposition

Different tools, same goal

3m

43. Practical Tips

(Implementation advice)

3m

44. Common Mistakes

(What goes wrong)

3m

45. Problem - Company Queries II

(CSES 1688)

3m1 problems

46. Core Idea - LCA via Euler Tour

(RMQ on depth array)

3m

47. Algorithm

(Full tour plus RMQ)

3m

48. Company Queries II - Implement Solution

(Submit your code)

3m1 problems

49. Lessons Learned

(Full tour power)

3m

50. Quiz: Combining with Data Structures

Knowledge check

2m1 problems

51. Section Recap

(What you learned)

3m

Practice Problems

2.
Subtree QueriesCSESmedium
3.
Path QueriesCSEShard
4.
Tree and QueriesCodeforceshard

Ready to start learning?

Access all 51 lessons with interactive content and progress tracking.