Max value node between two elements of BST
Given an array of integers that represent values of nodes in a Binary Search Tree. For example, If the given array is {9, 4, 17, 6, 5, 3, 7, 22, 20} Then BST created from above array will be as below Two numbers are given (along with the array), find largest number in the path […]
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 […]
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 […]
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 […]
Node with minimum value in a Binary Search Tree
Given a Binary Search Tree (BST), where will you find the node containing minimum value in the Tree? For example: If the tree is as given below Then answer is 1. Write a function that returns the least value in given BST.