How Binary Tree Problems Are Categorized in the LeetCode Master Study Path

The LeetCode Master repository organizes binary tree problems into six progressive stages—foundations, traversal techniques, core classics, construction and transformation, BST deep dive, and weekly reviews—creating a hierarchical learning track from recursion basics to advanced tree manipulation.

The youngyangyang04/leetcode-master repository structures its binary tree curriculum as a pedagogical ladder that mirrors how developers actually master these data structures. Rather than scattering problems randomly, the study path groups concepts into logical phases, with each markdown file in the problems/ directory representing a self-contained lesson that builds upon previous knowledge.

Theory Foundations

The journey begins with problems/二叉树理论基础.md, which establishes the conceptual bedrock before any coding occurs.

This file covers node definition, recursion basics, and the fundamental properties of binary trees (height, depth, and degree). Understanding these primitives is essential because every subsequent solution relies on this terminology. The repository assumes zero prior knowledge here, making it accessible to beginners who need to understand why TreeNode* left and TreeNode* right define the structure before attempting traversal.

Traversal Techniques

Once fundamentals are solid, the path moves to mastering movement patterns through the tree. This stage is split into four distinct files that exhaustively cover every traversal methodology:

  • problems/二叉树的递归遍历.md – Classic recursive implementations of pre-order, in-order, and post-order traversals using the function call stack.
  • problems/二叉树的迭代遍历.md – Stack-based iterative equivalents that simulate recursion manually, crucial for depth-limit scenarios.
  • problems/二叉树的统一迭代法.md – A unified iterative approach that handles all three traversal orders with a single algorithmic pattern (using nullptr markers to track visitation state).
  • problems/0102.二叉树的层序遍历.md – Breadth-first search (BFS) using a queue for level-by-level processing.

This systematic separation allows learners to compare recursive elegance against iterative control and understand when to apply each paradigm.

Core Classic Problems

With traversal mechanics mastered, the curriculum applies these patterns to standard property queries covered in files like problems/0104.二叉树的最大深度.md (maximum depth), problems/0110.平衡二叉树.md (balanced tree validation), problems/0111.二叉树的最小深度.md (minimum depth), problems/0222.完全二叉树的节点个数.md (complete tree node count), and problems/0404.左叶子之和.md (left leaf sum calculation).

These problems serve as the bridge between theory and application, requiring learners to recognize which traversal (depth-first vs. breadth-first) optimizes for each query type. For example, maximum depth naturally aligns with post-order recursion because you must calculate children's depths before the parent's.

Example: Maximum Depth (File: 0104.二叉树的最大深度.md)

// LeetCode 104: Maximum Depth of Binary Tree
class Solution {
public:
    int maxDepth(TreeNode* root) {
        if (!root) return 0;
        int left = maxDepth(root->left);
        int right = maxDepth(root->right);
        return max(left, right) + 1;
    }
};

This snippet demonstrates the recursive three-step pattern (base case, recursive calls, combination) that reappears throughout the track.

Construction and Transformation

The fourth stage focuses on mutating and building trees rather than merely querying them. Key files include problems/0106.从中序与后序遍历序列构造二叉树.md (building from traversal sequences), problems/0654.最大二叉树.md (maximum binary tree construction), and problems/0226.翻转二叉树.md (tree inversion).

These problems require understanding the structural relationships between parent and child nodes. For instance, constructing from inorder and postorder traversals demands knowing that the postorder's last element is the root, while the inorder sequence partitions left and right subtrees.

Example: Invert Binary Tree (File: 0226.翻转二叉树.md)

// LeetCode 226: Invert Binary Tree (iterative BFS)
class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        if (!root) return nullptr;
        queue<TreeNode*> q;
        q.push(root);
        while (!q.empty()) {
            TreeNode* cur = q.front(); q.pop();
            swap(cur->left, cur->right);
            if (cur->left)  q.push(cur->left);
            if (cur->right) q.push(cur->right);
        }
        return root;
    }
};

This demonstrates the 层序遍历 (level-order) technique from problems/0102.二叉树的层序遍历.md, reusing the BFS queue pattern in a destructive modification context.

Binary Search Tree (BST) Series

The fifth category narrows focus to BST-specific algorithms: validation (problems/0098.验证二叉搜索树.md), minimum absolute difference (problems/0530.搜索树的最小绝对差.md), mode calculation (problems/0501.二叉搜索树中的众数.md), lowest common ancestor (problems/0236.二叉树的最近公共祖先.md), and structural modifications like insertion, deletion, and trimming.

This separation is deliberate because BST problems leverage the binary search property (left < root < right), allowing for optimized O(log n) solutions that don't apply to general binary trees. The repository treats these as a specialization track only accessible after general tree mastery.

Weekly Summaries

Finally, consolidation occurs through files like problems/周总结/20200927二叉树周末总结.md and problems/周总结/20201010二叉树周末总结.md.

These weekly summaries cross-reference all previous stages, highlighting common pitfalls (such as confusing minimum depth with maximum depth logic) and comparing similar problems side-by-side. They serve as spaced repetition checkpoints within the problems/周总结/ directory.

Summary

  • Six-stage progression: Theory → Traversal → Core Problems → Construction → BST → Weekly Review.
  • File naming convention: Theory files use descriptive Chinese names (二叉树理论基础.md), while problem files use LeetCode ID prefixes (0104.二叉树的最大深度.md).
  • Self-contained lessons: Each markdown file includes algorithm analysis, complexity discussion, and multi-language implementations (C++, Java, Python, Go, JavaScript).
  • Prerequisite enforcement: The README's 二叉树 section orders these links sequentially, preventing learners from attempting construction problems before mastering traversals.
  • Repository location: All files reside under problems/ with weekly summaries isolated in problems/周总结/.

Frequently Asked Questions

Follow the README's 二叉树 section sequentially: start with problems/二叉树理论基础.md, then complete all four traversal technique files, proceed through core classics, then construction/transformation, followed by the BST series, and finish with weekly summaries. This order ensures you understand recursion and stack mechanics before attempting tree reconstruction.

How does the repository distinguish between general binary trees and BST problems?

General binary tree problems (depth, balance, inversion) appear in stages 1-4 and make no assumptions about node ordering. BST problems (validation, searching, trimming) are isolated in stage 5 because they exploit the left-subtree < root < right-subtree property, often requiring in-order traversal or boundary checking that doesn't apply to arbitrary trees.

Why are there three separate files for iterative traversals?

The repository separates 二叉树的迭代遍历.md (basic stack simulations) from 二叉树的统一迭代法.md (unified method using null markers) to teach two distinct mental models. The first teaches explicit stack management for each traversal order separately; the second demonstrates that all three traversals can share identical loop logic with minor ordering adjustments, reducing cognitive load once the basics are mastered.

Are solutions available in languages other than C++?

Yes. While the analysis examples show C++ implementations, each file (problems/0104.二叉树的最大深度.md, problems/0226.翻转二叉树.md, etc.) contains implementations in Java, Python, Go, and JavaScript. The repository treats C++ as the reference implementation but ensures the algorithmic logic translates directly across languages, often noting language-specific optimizations like Python's nonlocal variables for closure-based recursion.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →