Find height of the Binary Tree

 Given a Binary Tree, write code to calculate the height of the tree. Height of the binary Tree is the total number of levels in the Binary Tree. For example, Height of a NULL tree is 0. If a tree has only 1 node (root node) then the height is 1 and so on … […]

Level of node in a Binary Tree

Given a Binary Tree and a pointer to the Node in that tree. Write a function to find level of Node in the Tree. For Example, in the below tree In the Tree on left side: Root Node (Node with value 10) is at level-0 Nodes with values 5 and 30 are at level-1 Nodes […]

Node with maximum value in a Binary search tree

Earlier, we have seen how to find the minimum element in a Binary Search Tree. Write a function which will return the maximum value in a binary search tree. For example: For the below Binary search tree, the function should return 40 Structure of the Node of the Tree is as given below: struct Node […]

Similar Trees

Write function to check whether two trees are similar or not. The signature of the function should be as shown below: /** * Function to check whether two trees are similar or not. * @param r1, r2: Pointer to root nodes of two trees. * Returns true(1) if the two are similar, else false(0) */ […]

deleting a tree

Given a binary tree, write code to delete the entire tree. Structure of the node is as given below: struct Node { int data; Node* lptr; // ptr to LEFT sub-tree Node* rptr; // ptr to RIGHT sub-tree };

Level-wise traversal of a binary tree

Write an Algorithm to print the elements of a binary tree in level-wise order. For example if the Binary tree is as given below: Then the traversal should be in the following order:

Diameter of a Tree

Diameter of a tree is the longest path (Number of nodes) between two leaf nodes of the tree. It is also called width of the tree. For example, diameter of the below tree is 6 (red color nodes form part of the diameter) A / \ B C / / \ D E F \ […]

Mirror of a Binary Tree

Given a Binary Tree, write a function which will convert that tree to its Mirror Tree. For Example: If the Binary Tree is 1 / \ 2 3 / \ 4 5 Then the Mirror is 1 / \ 3 2 / \ 5 4