# 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

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 […]

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 […]

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 […]

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 […]

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 […]

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

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.

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 […]

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 … […]