Understanding the stateful postorder traversal pattern
The stateless postorder traversal can only share data between nodes by passing a copy of processed values up from the child nodes to the parent node. However, there are some problems where, to process a node, we may also need to read or update some state variables that can be accessed from all nodes. The stateful postorder traversal is ideal for solving such problems, as the same copy of data is shared between all nodes throughout the traversal, which can be read or updated when returned values from the left and right subtrees are aggregated in a node.
The order of processing of nodes in postorder traversal
In this lesson, we will learn more about using the stateful postorder traversal technique to solve binary tree problems and how to identify a problem as a postorder pattern problem.
The stateful postorder traversal technique
Liking the course? Check our discounted plans to continue learning.