# Category Archives: Binary Search Tree

## Largest number less than or equal to N in BST (Iterative Approach)November 13, 2017

We have a binary search tree and a number N. Our task is to find the greatest number in the binary search tree that is… Read More »

## Maximum Unique Element in every subarray of size K

Given an array and an integer K. We need to find the maximum of every segment of length K which has no duplicates in that… Read More »

## Count greater nodes in AVL treeOctober 24, 2017

In this article we will see that how to calculate number of elements which are greater than given value in AVL tree. Examples: Input :… Read More »

## Left Leaning Red Black Tree (Insertion)

Prerequisites : Red – Black Trees. A left leaning Red Black Tree or (LLRB), is a variant of red black tree, which is a lot… Read More »

## Check if two BSTs contain same set of elementsOctober 20, 2017

Given two Binary Search Trees consisting of unique positive elements, we have to check whether the two BSTs contains same set or elements or not.… Read More »

## Minimum Possible value of |ai + aj – k| for given array and k.October 6, 2017

You are given an array of n integer and an integer K. Find the number of total unordered pairs {i, j} such that absolute value… Read More »

## Shortest distance between two nodes in BSTOctober 3, 2017

Given a Binary Search Tree and two keys in it. Find the distance between two nodes with given two keys. It may be assumed that… Read More »

## Construct BST from its given level order traversalOctober 2, 2017

Construct the BST (Binary Search Tree) from its given level order traversal. Examples: Input : arr[] = {7, 4, 12, 3, 6, 8, 1, 5,… Read More »

## Count pairs from two BSTs whose sum is equal to a given value xSeptember 7, 2017

Given two BSTs containing n1 and n2 distinct nodes respectively. Given a value x. The problem is to count all pairs from both the BSTs… Read More »

## Remove all leaf nodes from the binary search treeSeptember 6, 2017

We have given a binary search tree and we want to delete the leaf nodes from the binary search tree. Examples: Input : 20 10… Read More »

## Largest number in BST which is less than or equal to NJuly 5, 2017

We have a binary search tree and a number N. Our task is to find the greatest number in the binary search tree that is… Read More »

## Check if an array represents Inorder of Binary Search tree or notJune 29, 2017

Given an array of N element. The task is to check if it is Inorder traversal of any Binary Search Tree or not. Print “Yes”… Read More »

## Convert BST to Min HeapJune 17, 2017

Given a binary search tree which is also a complete binary tree. The problem is to convert the given BST into a Min Heap with… Read More »

## Find median of BST in O(n) time and O(1) spaceJune 16, 2017

Given a Binary Search Tree, find median of it. If no. of nodes are even: then median = ((n/2th node + (n+1)/2th node) /2 If… Read More »

## Leaf nodes from Preorder of a Binary Search Tree

Given a Preorder traversal of a Binary Search Tree. The task is to print leaf nodes of the Binary Search Tree from the given preorder.… Read More »