Close

Mirror image of a binary tree

Given a binary tree, how to convert it to it’s mirror image?For example consider the following binary tree and it’s mirror image. Here simply, the left and right sub trees of each node are inverted. So we have to simply invert the given binary tree. It is a simple implementation problem. Using recursion we can…

Checking if a binary tree is balanced

Given a binary tree, how do we check if it is balanced or not? We say that a binary tree is balanced if height difference of left  and the right sub-trees is at most 1 at  any node. Consider the following examples   1          1               1             1  /                       /              …

Right view of the binary tree

Given a binary tree, how do we print the right view of it?For example, consider the simple binary tree below    1 / 2   3 The right view of this is 1, 3. Similarly consider one more example             1          /           2    5        /          3   4  Right view for this tree contains…

Left view of a binary tree

Given a binary tree, how do we print the left view of it?For example, consider the simple binary tree below    1 / 2   3 The left view of this is 1, 2. Similarly consider one more example             1          /           2    3             /             4   5Left view for this tree contains 1, 2,…