Checking if a Binary Tree is foldable

A binary tree is foldable if the left subtree and right subtree are mirror images of each other. An empty tree is also foldable. Below binary trees are foldable since both have a left subtree that is the mirror image of right subtree.

folded
folded-2
However, below binary tree is not foldable.
folded-3
We can check if a binary tree is foldable or not in two ways:

By changing the left subtree to its mirror equivalent. Then checking if the mirror is equivalent to te right subtree.Compare and check if right and left s...
 •  0 comments  •  flag
Share on Twitter
Published on March 26, 2021 09:54
No comments have been added yet.