Roadmap › Stage 6: Trees › Pattern 27 of 53
DSA pattern guide

Tree — DFS

Depth, paths, diameter, balanced or symmetric checks.

Stage 6 · Trees13 problems7 Easy · 4 Medium · 2 Hard

Use it when

Depth, paths, diameter, balanced or symmetric checks.

Key idea

Recurse to the children and return what the parent needs (height, sum). Update a global answer on the way back.

Practice problems, in order

  1. Inorder TraversalEasy
  2. Symmetric TreeEasy
  3. Diameter of Binary TreeEasy
  4. Balanced Binary TreeEasy
  5. Maximum Depth of Binary TreeEasy
  6. Path SumEasy
  7. Subtree of Another TreeEasy
  8. Path Sum IIMedium
  9. Path Sum IIIMedium
  10. Count Complete Tree NodesMedium
  11. All Nodes Distance K in Binary TreeMedium
  12. Binary Tree Maximum Path SumHard
  13. Binary Tree CamerasHard

How to practise this pattern

  1. Read the problem and look for the signal above before writing any code.
  2. Say the brute force out loud, with its time complexity, then ask what work it repeats.
  3. Apply the key idea and write the optimised version yourself.
  4. If you're stuck for more than 10 minutes, take one small hint, not the full solution.
  5. Move to the next problem only when you can explain why this pattern fits.

Stuck on one of these?

The AlgoSolveo extension (free, launching soon) sits beside the LeetCode problem and gives the smallest hint that gets you moving, never the full answer. Solved problems tick off on your roadmap.

Join the extension waitlistTrack it on the roadmap
← Previous patternDoubly Linked ListNext pattern →Tree — BFS / Level Order