Skip to main content

Check if binary tree is Foldable Binary Tree

A binary tree is foldable if the left subtree and the right subtree of the root node are structurally mirror images of each other. In other words, if we fold the binary tree along the middle line, the left subtree will coincide with the right subtree.

Check if binary tree is Foldable Binary Tree

To check whether a binary tree is foldable or not, we need to compare the structure of the left and right subtrees. We can do this by traversing the tree in a recursive manner and comparing the left subtree of the left child with the right subtree of the right child, and the right subtree of the left child with the left subtree of the right child. If at any point we find a mismatch, then the tree is not foldable.

Program List





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment