Question: Given a binary tree node and root node, get the parent node of that node. Solution: Solution is very simple. Before we go to the child node of any parent node, we check if the children nodes is equal to given value. If it is …
Question: Given a binary tree root node, check if all Leaf Nodes are at same level in Binary tree Solution: We can solve this question with the help of pre-order traversal. First we visit the left leaf and update the level value, and then check with …
Question: Given a binary tree root node, check if the tree is a height balanced tree. What is a height balanced tree? A tree is called as height balanced tree if the difference between left height and right height should not be more than 1. It …
Question: Given a binary tree root node and 2 level, print the nodes between those levels. Example: Consider the image given below If given level is 2 and 3 the nodes that should be printed are: 10, 25, 7, 15, 18, 30 Solution: We do this …
Question: Given a binary tree root node, get the maximum width of that tree Example: Consider the image given below Width at level 1 is 1. Because it has only 1 node. Width at level 2 is 2. Because it has only 2 nodes. Width at …
Question: Given a binary tree root node, get the level of the node. Example: Consider the image given below If the given node is “25” level is 2 If the given node is “15” level is 3 Steps to get the level of a given node: …
Question: Given a binary tree root node, delete that tree Example: Consider the tree given below. How do you delete it? Here if you delete root node first, the you will loose link to left and right children. So we need to user post order traversal. …
Question: Given a binary tree root node, convert that tree to it’s mirror. Example: Consider the image given below and its mirror. Above image shows a tree and it’s mirror tree. From the above image we can see that, except the root node, all the other …
Question: Given a binary tree root node, perform Post Order traversal by using stacks. Example: Consider the image given below: PostOrder Traversal (Left, Right, Root): 7 15 10 18 30 25 16 Now lets see how to perform Post Order Traversal: (Left, Right, Root) In Post-Order …