Hide Index
- Understanding the problem
- Understanding iterative preorder traversal
- Implement iterative preorder traversal
- Understanding iterative inorder traversal
- Implement iterative inorder traversal
- Understanding iterative postorder traversal
- Implement iterative postorder traversal
- Understanding level order traversal
- Implement level order traversal
- Challenges in construction from preorder traversal
- Challenges in construction from inorder traversal
- Challenges in construction from postorder traversal
- Understanding construction using preorder and inorder traversal
- Construct tree using preorder and inorder traversal
- Understanding construction using postorder and inorder traversal
- Construct tree using postorder and inorder traversal
Identifying the stateless root to leaf path pattern
The stateless root-to-leaf path technique can only solve a certain type of binary tree problem. These are generally easy or medium problems where we need to find the aggregated value of a function f over all nodes in every root-to-leaf path. For most problems, we need to further aggregate these aggregated values over another function g.
The stateless solution works by incrementally aggregating values over function f by passing the aggregated value of a path down from the parent to child nodes, computing the root-to-leaf aggregate on reaching a leaf node, and returning and merging all root-to-leaf path aggregates using the function g on the way up.
If the problem statement or its solution follows the generic template below, it can be solved by applying the stateless root-to-leaf path technique.
Given a binary tree, find the aggregated value of a function
f over all root-to-leaf paths and further aggregate these aggregated values over a function g.Example
Liking the course? Check our discounted plans to continue learning.