##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Binary trees are the foundation of hierarchical data. Learn the three traversal orders and recursion.
Tree DP problem maximizing sum of edge weights. Teaches greedy decisions at each node based on subtree structure.
Preorder, inorder, postorder
Find tree diameter using two BFS/DFS. Fundamental technique used in many tree optimization problems.
Count pairs at distance k using centroid decomposition or DP. Classic tree distance query problem.
Check if vertices lie on a root-to-leaf path. Teaches DFS ordering and LCA concepts.
DFS with constraint tracking. Count valid root-to-leaf paths avoiding consecutive marked nodes.
LCA with binary lifting for distance queries. Essential technique for tree path problems.
Tree DP counting valid edge removals. Teaches state tracking for subtree partitioning.
Euler tour + segment tree for subtree updates. Flattening tree to array for range queries.
Greedy selection on tree with depth and subtree size. Maximize happiness by choosing k industrial cities.
Euler tour with bitmask segment tree. Count distinct colors in subtrees efficiently.
Path counting with LCA and difference arrays. Count edge usage across multiple paths.
Tree operations with segment tree on Euler tour. Fill subtree, empty vertex, query operations.
Master iterative inorder with explicit stack. Foundation for Morris traversal understanding.
BFS on trees using queue. Essential pattern for level-by-level processing.
Simple recursion demonstrating tree height calculation. Foundation for tree DP.
Classic tree construction using traversal properties. Teaches index mapping optimization.
Fundamental LCA algorithm. Returns first node where both targets found in different subtrees.
Classic tree DP computing maximum path through each node. Global vs return value distinction.
Diameter as max(left_height + right_height) at any node. Simple but important tree property.
Design problem for tree encoding. Multiple approaches: preorder with nulls, level-order, etc.