# Category Archives: Binary Search Tree

## Sum of k smallest elements in BSTJanuary 14, 2017

Given Binary Search Tree. The task is to find sum of all elements smaller than and equal to Kth smallest element. Examples: Input : K… Read More »

## Check whether BST contains Dead End or notJanuary 2, 2017

Given a Binary search Tree that contains positive integer values greater then 0. The task is to check whether the BST contains a dead end… Read More »

## Find the closest element in Binary Search TreeDecember 31, 2016

Given a binary search tree and a target node K. The task is to find the node with minimum absolute difference with given target value… Read More »

## Find pairs with given sum such that pair elements lie in different BSTsDecember 15, 2016

Given two Binary Search Trees (BST) and a given sum. The task is to find pairs with given sum such that each pair elements must… Read More »

## Check if given sorted sub-sequence exists in binary search tree

Given a binary search tree and a sorted sub-sequence. the task is to check if the given sorted sub-sequence exist in binary search tree or… Read More »

## Replace every element with the least greater element on its rightJuly 20, 2016

Given an array of integers, replace every element with the least greater element on its right side in the array. If there are no greater… Read More »

## In-place Convert BST into a Min-HeapJune 8, 2016

Given a Binary Search Tree, convert it into a Min-Heap containing the same elements in O(n) time. Do this in-place. Input: Binary Search Tree 8… Read More »

## Count inversions in an array | Set 2 (Using Self-Balancing BST)December 17, 2015

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count… Read More »

## Print Common Nodes in Two Binary Search TreesSeptember 10, 2015

Given two Binary Search Trees, find common nodes in them. In other words, find intersection of two BSTs. Example: Recommended: Please solve it on “PRACTICE”… Read More »

## How to implement decrease key or change key in Binary Search Tree?September 7, 2015

Given a Binary Search Tree, write a function that takes following three as arguments: 1) Root of tree 2) Old key value 3) New Key… Read More »

## Construct all possible BSTs for keys 1 to NJuly 17, 2015

In this article, first count of possible BST (Binary Search Trees)s is discussed, then construction of all possible BSTs. How many structurally unique BSTs for… Read More »

## K’th smallest element in BST using O(1) Extra SpaceJuly 16, 2015

Given a Binary Search Tree (BST) and a positive integer k, find the k’th smallest element in the Binary Search Tree.

## Count BST subtrees that lie in given rangeJuly 4, 2015

Given a Binary Search Tree (BST) of integer values and a range [low, high], return count of nodes where all the nodes under that node… Read More »

## Count BST nodes that lie in a given rangeJuly 2, 2015

Given a Binary Search Tree (BST) and a range, count number of nodes that lie in the given range.

## Second largest element in BSTJune 17, 2015

Given a Binary Search Tree(BST), find the second largest element. Examples: Input: Root of below BST 10 / 5 Output: 5 Input: Root of below… Read More »