A Binary Search Tree (BST) is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child and the topmost node in the tree is called the root. It additionally satisfies the binary search property, which states that the key in each node must be greater than or equal to any key stored in the left sub-tree, and less than or equal to any key stored in the right sub-tree.

Binary search trees allows fast lookup, addition and removal of items. They keep their keys in sorted order, so that lookup and other operations can use the principle of Binary Search: when looking for a key in a tree (or a place to insert a new key), they traverse the tree from root to leaf, making comparisons to keys stored in the nodes of the tree and deciding, on the basis of the comparison, to continue searching in the left or right subtrees. On average, this means that each comparison allows the operations to skip about half of the tree, so that each lookup, insertion or deletion takes time proportional to the logarithm of the number of items stored in the tree. This is much better than the linear time required to find items by key in an (unsorted) array, but slower than the corresponding operations on hash tables.

In this post, we have list out commonly asked interview questions on Binary Search Tree –

- Insertion in BST

- Search given key in BST

- Deletion from BST

- Construct balanced BST from given keys

- Determine if given Binary Tree is a BST or not

- Check if given keys represents same BSTs or not without building the BST

- Find inorder predecessor for given key in a BST

- Find Lowest Common Ancestor (LCA) of two nodes in a Binary Search Tree

- Find Kโth smallest and Kโth largest element in BST

- Floor and Ceil in a Binary Search Tree

- Find optimal cost to construct binary search tree

- Convert a Binary Tree to BST by maintaining its original structure

- Remove nodes from BST that have keys outside the valid range

- Find a pair with given sum in a BST

- Find inorder successor for given key in a BST

- Replace every element of an array with the least greater element on its right

- Fix a binary tree that is only one swap away from becoming a BST

- Update every key in BST to contain sum of all greater keys

**Thank you for being with us. ๐**

## Leave a Reply

Great Blog !

But in the current post, description is of Binary Search and Questions are of Binary Search Tree(BST)

Thanks a lot for bringing this to our notice. We have updated the description. Happy coding ๐