Identifying the stateless postorder traversal pattern


The postorder traversal technique is very versatile and can solve a wide variety of binary tree problems. These are generally easy or medium problems where we need to process every node using the aggregated value of some function f over its left and right subtrees. Also, the stateless implementation can only solve problems where no state (common) information is shared between all nodes, and each node has access to only its copy of local variables. 

If the problem statement or its solution follows the generic template below, it can be solved by applying the stateless postorder traversal technique.

Template:

Given a binary tree, process every node using the aggregated value of a function f over its left and right subtrees. The processing of a leaf or null node should be trivial, meaning it should have a known solution, and no state information must be shared between nodes.

Liking the course? Check our discounted plans to continue learning.