Skip to content
C Codeloom

Topics / Trees

🌳

Trees

Binary trees, BSTs, traversals, and the recursion patterns that solve most tree problems in 10 lines.

Why learn Trees?

  • Foundation for graphs and dynamic programming on graphs.

  • Most tree problems are 5–15 line recursive solutions once you see the pattern.

  • BSTs appear inside databases, file systems, and indexes.

What you can build with Trees

Tree traversals (DFS, BFS, level-order) BSTs and balanced trees Trie-based prefix problems

Trees tutorials

9 articles

Hand-written tutorials, ordered as a recommended learning path.

  1. 01 Binary Trees — Intro A practical introduction to binary trees — the TreeNode class, terminology (full, complete, perfect, balanced), height vs depth, BSTs, and the small calculations you need to reason about tree problems.
  2. 02 Tree Traversals A practical guide to the four canonical binary tree traversals — recursive and iterative versions, when to use each, and the patterns that make them click.
  3. 03 Trees — Practice Eight classic binary tree interview problems with examples, approach notes, and clean Python solutions — max depth, same tree, invert, symmetric, path sum, LCA, validate BST, and serialize/deserialize.
  4. 04 LC 98 — Validate BST LeetCode 98 in full — the seductive wrong answer, the correct min/max bounds approach, and how to defend it in an interview.
  5. 05 LC 235 — LCA of BST LeetCode 235 walked through end to end — why BST ordering collapses LCA into a one-line traversal, and the iterative version that needs zero extra space.
  6. 06 LC 230 — Kth Smallest BST LeetCode 230 in detail — the inorder traversal trick, the iterative early-exit version, and the follow-up that haunts FAANG interviews.
  7. 07 LC 297 — Serialize Tree LeetCode 297 fully unpacked — the preorder-with-nulls encoding, the iterator-driven decoder, and why level-order is a worse choice than it looks.
  8. 08 LC 112 — Path Sum LeetCode 112 in detail — the DFS-with-decrement trick, why the leaf condition is the whole problem, and the variants that build on it.
  9. 09 LC 102 — Level Order LeetCode 102 in detail — the queue-with-size BFS pattern, why DFS still works, and how this template extends to zigzag and right-side view.