# Category Archives: Binary Search Tree

## Add all greater values to every node in a given BSTSeptember 12, 2013

Given a Binary Search Tree (BST), modify it so that all greater values in the given BST are added to every node. For example, consider… Read More »

## Check for Identical BSTs without building the treesJune 23, 2013

Given two arrays which represent a sequence of keys. Imagine we make a Binary Search Tree (BST) from each array. We need to tell whether… Read More »

## Remove BST keys outside the given rangeMarch 29, 2013

Given a Binary Search Tree (BST) and a range [min, max], remove all keys which are outside the given range. The modified tree should also… Read More »

## Find a pair with given sum in a Balanced BSTMarch 10, 2013

Given a Balanced Binary Search Tree and a target sum, write a function that returns true if there is a pair with sum equals to… Read More »

## Find if there is a triplet in a Balanced BST that adds to zeroMarch 9, 2013

Given a Balanced Binary Search Tree (BST), write a function isTripletPresent() that returns true if there is a triplet in given BST with sum equals… Read More »

## Convert a BST to a Binary Tree such that sum of all greater keys is added to every keyJanuary 1, 2013

Given a Binary Search Tree (BST), convert it to a Binary Tree such that every key of the original BST is changed to key plus sum of all greater keys in BST

## Floor and Ceil from a BSTOctober 17, 2012

There are numerous applications we need to find floor (ceil) value of a key in a binary search tree or sorted array.

## Construct BST from given preorder traversal | Set 2October 11, 2012

Given preorder traversal of a binary search tree, construct the BST. For example, if the given traversal is {10, 5, 1, 7, 40, 50}, then… Read More »

## Construct BST from given preorder traversal | Set 1

Given preorder traversal of a binary search tree, construct the BST. For example, if the given traversal is {10, 5, 1, 7, 40, 50}, then… Read More »

## Two nodes of a BST are swapped, correct the BSTSeptember 14, 2012

Two of the nodes of a Binary Search Tree (BST) are swapped. Fix (or correct) the BST.

## Check if each internal node of a BST has exactly one childAugust 5, 2012

Given Preorder traversal of a BST, check if each non-leaf node has only one child. Assume that the BST contains unique entries.

## Binary Tree to Binary Search Tree ConversionJune 15, 2012

Given a Binary Tree, convert it to a Binary Search Tree. The conversion must be done in such a way that keeps the original structure… Read More »

## Merge two BSTs with limited extra spaceJune 1, 2012

Given two Binary Search Trees(BST), print the elements of both BSTs in sorted form. The expected time complexity is O(m+n)

## Merge Two Balanced Binary Search TreesMarch 30, 2012

You are given two balanced binary search trees e.g., AVL or Red Black Tree. Write a function that merges the two given balanced BSTs into… Read More »

## Find the largest BST subtree in a given Binary Tree | Set 1February 17, 2012

Given a Binary Tree, write a function that returns the size of the largest subtree which is also a Binary Search Tree (BST). If the… Read More »