Printing border nodes of Binary Tree
Given a Binary tree, Write code to print all the boundary nodes in counter clockwise order. For example, for the below binary tree, The output should be: A, B, D, H, I, F, G, C, A . Boundary Nodes are traversed in anti-clockwise order.
Null pointers in a Binary tree
Given a Binary Tree with n Nodes (you may arrange these nodes any way you want to). How many NULL pointers will be there ? You want options also :).. here are the options A) n B) n+1 C) n-1 D) None
Print edge nodes (boundary nodes) of a Binary Tree
Given a Binary Tree. Write code to print the boundary nodes of the Tree. For example, if the Binary tree is __30__ / \ / \ 20 40 / \ / \ 10 25 35 50 / \ \ / 5 15 28 41 The output should be: 30 20 10 5 15 28 35 […]
Print all nodes at distance k from root of a Binary Tree
Given a Binary Tree and a positive integer ‘k’, write code which will print all the nodes which are at distance ‘k’ from the root. For example: For Binary Tree on the right side, Following are the nodes which should get printed for the below values of ‘k’ k output — ——- 0 10 1 […]
Check if a Binary Tree is Binary Search Tree
Given a Binary Tree, write code to check if it is Binary Search Tree or not ? Binary search tree is a binary tree with following restrictions All values in the left subtree are Less than the value at root. All values in the Right subtree are Greater than the value at root. Both Left […]
Convert a Binary Tree to Binary Search Tree
Given a Binary Tree, write code to convert it to Binary Search Tree such that the structure of the tree remains the same. For example: Both the below trees 5 10 / \ / \ 8 10 5 30 / \ \ / \ \ 4 30 1 8 40 1 / / 40 4 […]
Lowest Common Ancestor in Binary Search Tree
In a Binary Search Tree, you are given the values of two nodes. Write a code which will return the Lowest Common Ancestor of both the nodes. For Example: If the BST is as shown on the right and Nodes are 4 and 8, The output should be: 5 4 and 8 has two common […]
Print all possible root-to-leaf paths in a binary tree
Given a Binary Tree, write code to print all root-to-leaf paths possible in the tree. For Example, For the Binary Tree given on the right side, the output should be 10, 5, 4, 1 10, 5, 8 10, 30, 40
Number of nodes in a binary tree
Write a function which will return the total number of nodes in a Binary tree. For example, the Binary tree on the right has 7 nodes.
check if all nodes of a tree has only one child
Given the PreOrder traversal of a binary search tree (in the form of a tree), check if all the nodes (except the last) of the tree has exactly one child. For Example: If the Preorder traversal of the tree is given as below: {50, 25, 45, 30, 27, 29} The the output should be: TRUE […]