## BST to a Tree with Sum of all Smaller Keys

In this problem we have given a Binary Search Tree, write an algorithm to convert best to a tree with sum of all smaller keys. Example Input Output Pre-order : 19 7 1 54 34 88 Naive Approach Traverse all the nodes one by one in any traversal form, and …

## Find the node with minimum value in a Binary Search Tree

Given a Binary Search Tree, write an algorithm to find the node with the minimum value in a given binary search tree. Example Input Output 5 Naive Approach A simple approach is to do a tree traversal and find the node with the minimum value among all the nodes. This …

## Reverse a Path in BST using Queue

In reverse a path in BST using queue problem we have given a Binary Search Tree and node, write an algorithm to reverse the path from root to the given node. Assume that the node exists in the BST. Example Input Target Node = 12 Output In-order traversal before the …

## Kth Smallest Element in a BST

In this problem, we have given a BST and a number k, find the kth smallest element in a BST. Examples Input tree[] = {5, 3, 6, 2, 4, null, null, 1} k = 3 Output 3 Input tree[] = {3, 1, 4, null, 2} k = 1 Output 1 …

## Lowest Common Ancestor in Binary Search Tree

Given the root of a binary search tree and two nodes n1 and n2, find the LCA(Lowest Common Ancestor) of the nodes in a given binary search tree. Example Naive Approach for Lowest Common Ancestor in Binary Search Tree Find the LCA(n1, n2) using the optimal approach to find LCA …

## Binary Search Tree

A binary search tree is a Binary tree with some rules that allows us to maintain the data in a sorted fashion. As it is a binary tree hence, a node can have at max 2 children. Structure of a Binary Search Tree node   Rules for Binary tree to …

## Recover Binary Search Tree

Consider a binary search tree, two nodes of the tree have been swapped, design an algorithm to recover the binary search Tree. Example Consider the binary search tree given below whose two nodes have been swapped as input. Incorrect nodes on the BST are detected(highlighted) and then swapped to obtain …

## Trim a Binary Search Tree

In Trim a Binary Search Tree problem we have given a binary search tree and a lower (as L) and higher bound (as R) of a range of integer values, trim the BST so that all its elements lie in the range[L,R] (R >= L). If the given BST root …

## Convert Sorted List to Binary Search Tree

Problem Given a linked list. The elements of the linked list are in increasing order. Convert the given linked list into a highly balanced binary search tree. A highly balanced binary search tree is a binary search tree in which the difference between the depth of two subtrees of any …

## Unique Binary Search Trees

Firstly we have to find the total number of counts to form a unique binary search tree. After it, we construct all possible unique BST. First of all, we have to know the construction of BST. In a Binary Search Tree, the nodes present in the left subtree wrt. any …