Understanding the simultaneous traversal pattern


We traverse a binary tree to search for and perform operations on its nodes. However, there are cases where we may need to operate on nodes from two binary trees at once. This requires us to traverse both the binary trees simultaneously and apply some function f on corresponding nodes in both the trees. Both these trees may or may not have the same structure, and the decision to traverse further in any of them depends on the outcome of the function f. The simultaneous tree traversal technique can be used to traverse both the trees at once using a single recursive function.

The simultaneous traversal pattern is a classification of problems that can be solved using the simultaneous tree traversal technique.
Loading Image

The simultaneous traversal technique traverses two trees simultaneously.

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