# Category Archives: Binary Search Tree

## 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 »

## Data Structure for a single resource reservationsMay 28, 2015

Design a data structure to do reservations of future jobs on a single machine under following constraints. 1) Every job requires exactly k time units… Read More »

## How to handle duplicates in Binary Search Tree?May 11, 2015

In a Binary Search Tree (BST), all keys in left subtree of a key must be smaller and all keys in right subtree must be… Read More »

## Advantages of BST over Hash TableApril 1, 2015

Hash Table supports following operations in Θ(1) time.

## K’th Largest Element in BST when modification to BST is not allowedMarch 19, 2015

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

## Given n appointments, find all conflicting appointmentsDecember 8, 2014

Given n appointments, find all conflicting appointments.

## C Program for Red Black Tree InsertionAugust 4, 2014

Following article is extension of article discussed here. In AVL tree insertion, we used rotation as a tool to do balancing after insertion caused imbalance.… Read More »

## Inorder predecessor and successor for a given key in BSTJuly 25, 2014

I recently encountered with a question in an interview at e-commerce company. The interviewer asked the following question:

## Transform a BST to greater sum treeJune 27, 2014

Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node.

## Binary Search Tree | Set 2 (Delete)January 30, 2014

We have discussed BST search and insert operations. In this post, delete operation is discussed. When we delete a node, there possibilities arise.

## Binary Search Tree | Set 1 (Search and Insertion)

The following is definition of Binary Search Tree(BST) according to Wikipedia Binary Search Tree, is a node-based binary tree data structure which has the following… Read More »