Binary Search Tree

A binary search tree is a specific type of binary tree that is either empty, or each node in the tree contains a key, and all keys in the left subtree are less (numerically or alphabetically) than the identifier in the root node; all keys in the right subtree are greater than the identifier in the root node and the left and right subtrees are also binary search trees.

Introduction to Binary Search tree

By Ranjul Arumadi

● Published At Oct 2021

A binary tree is a non-linear data structure. A Binary search tree is an improved version of a binary tree that provides efficient methods to implement various operations in a data structure. It has multiple applications.... Keep reading ..

Difference between binary tree and binary search tree

By Shreya Deep

● Published At Dec 2021

In this article, we will compare binary trees and binary search trees... Keep reading ..

Inbuilt Binary Search in Different Languages

By Riya

● Published At Feb 2022

This article will discuss binary search and inbuilt binary search functions in different languages like C++, java.... Keep reading ..

Operations on Binary Search Tree

We can mainly do three types of operations on Binary Search Trees. We can insert, delete and search for an element in the Binary Search Tree. The time complexity for all the operations(Insert, Delete, Search) is O(Log(N)) where N is the total number of Nodes in the Tree.

Deletion in Binary Search Tree

By Souhard Swami

● Published At Apr 2022

The blog deals with the Deletion in the Binary search Tree and determines the best method for the Deletion in the Binary Search Tree.
... Keep reading ..

Binary Search Tree | Iterative Delete

By Apoorv

● Published At Feb 2022

In this article, we will discuss the solution to delete a node iteratively in the binary search tree along with its time complexity and space complexity ... Keep reading ..

Implementing Backward Iterator in BST

By Riya

● Published At Feb 2022

This article will discuss how to implement a backward iterator in BST, its C++ implementation, and its time and space complexity.... Keep reading ..

Implementing Forward Iterator in BST

By Apoorv

● Published At Feb 2022

This article will discuss the low-level design of BST iterator which has a lot of functions like returning the current pointer in BST, next pointer in BST, and isend() function, which tells if there is a node present at the right of the current node ... Keep reading ..

Insertion in Binary Search Tree

By Malay Gain

● Published At Nov 2021

One of the fundamental operations of the Binary Search Tree is to insert node binary search trees.... Keep reading ..

Insert a node in Binary Search Tree Iteratively

By Vaibhav Agarwal

● Published At Dec 2021

In this article, we will discuss the problem of inserting a node in the binary search tree iteratively.... Keep reading ..

Construct BST from the given pre-order traversal

By Gaurish Anand

● Published At Dec 2021

You are given a pre-order traversal of a BST. Construct the BST using this pre-order traversal array.... Keep reading ..

Construct a BST from given postorder traversal using Stack

By Aditya Narayan Joardar

● Published At Dec 2021

This article discusses how to construct a BST from given postorder traversal using Stack.... Keep reading ..

Problems

Binary Search Trees is a very famous topic from which questions are asked in the interviews of the Top Product-Based Companies. Hence, you must solve different problems on the Binary Tree such as searching for a key in a Binary Search Tree, Diametre of a Binary Search Tree, etc.
Let us explore more problems to expertise in the same!

Lowest Common Ancestor in a Binary Search Tree

By aniket verma

● Published At Oct 2021

This article will brief you on finding the Lowest Common Ancestor in a Binary Search Tree.
... Keep reading ..

Finding inorder predecessor of a node in a Binary Search Tree

By Akshat Chaturvedi

● Published At Nov 2021

In this blog, we’ll see what an inorder predecessor of a node in a binary search tree is and how we can find it using a simple recursive approach.... Keep reading ..

Finding Inorder Successor of a node in a Binary Search Tree

By Akshat Chaturvedi

● Published At Nov 2021

In this blog, we will learn what an inorder successor of a given key in Binary Search Tree is and how to code it in C++.... Keep reading ..

Number of Binary Search Trees of height H consisting of H+1 nodes

By Firdausia Fatima

● Published At Jan 2022

In this blog, we’ll see how maths can ease our work by solving an exciting problem, the Number of Binary Search Trees of height H consisting of H+1 nodes.... Keep reading ..

Range Sum of BST

By Alisha Chhabra

● Published At Oct 2021

In this article, we’ll calculate the Range Sum of BST using the recursive approach. ... Keep reading ..

Flatten a Binary Search Tree to Convert the Tree into a Wave List in Place Only

By Saksham Gupta

● Published At Jan 2022

In this blog, we will discuss how we can solve the problem ‘Flatten a Binary Search Tree to convert the tree into a wave list in place only ’ in the most efficient way possible.
... Keep reading ..

Flattening BST in Sorted List

By Deepanshu Dhingra

● Published At Jan 2022

A complete walkthrough of the problem - Flattening BST in Sorted List. This article will discuss the approaches to solve the problem along with the discussion for Space and Time Complexities.
... Keep reading ..

Row with the maximum number of 1’s

By Sandeep kamila

● Published At Nov 2021

This article covers different approaches and implementations of the problem row with the maximum number of 1’s in C++.... Keep reading ..

Create a wave array from the given Binary Search Tree

By Ishita Chawla

● Published At Dec 2021

This blog will discuss the problem to create a wave array from the given Binary Search Tree.
... Keep reading ..

Sum of all nodes with smaller values at a distance ‘K’ from the given node in BST

By Ujjawal Gupta

● Published At Jan 2022

In this blog, we will learn to solve a problem based on a Binary search tree.
... Keep reading ..

Median of All Nodes from a Given Range in a BST

By Firdausia Fatima

● Published At Jan 2022

In this blog, we’ll be solving a tree traversal problem, the median of all nodes from a given range in a BST.... Keep reading ..

Print All Odd Nodes Of Binary Search Tree

By Harsh Goyal

● Published At Dec 2021

This article will discuss the print all the odd nodes of the binary search tree problem and the efficient way to solve this problem.
... Keep reading ..

Print all the even nodes of a Binary Search Tree

By Sandeep kamila

● Published At Dec 2021

This article covers the approach of printing all the even nodes of a Binary search tree and its code in C++.... Keep reading ..

Node with the maximum value in a Binary Search Tree

By Sandeep kamila

● Published At Dec 2021

This article covers the implementation of finding the node with maximum value in a binary search tree with an explanation and its C++ code.
... Keep reading ..

Sum and the Product of minimum and maximum elements of a Binary Search Tree

By Sandeep kamila

● Published At Dec 2021

This article covers the approach and implementation of finding the sum and the product of a Binary search tree’s minimum and maximum elements with its C++ code.... Keep reading ..

Find Closest Smaller Value For Every Element In Array

By Harsh Goyal

● Published At Dec 2021

This article will discuss to find the closest smaller value for every element in the array and various ways to solve this problem... Keep reading ..

Find Closest Value For Every Element In Array

By Harsh Goyal

● Published At Dec 2021

This article will discuss the find the closest value for every element in the array problem and various ways to solve this problem.
... Keep reading ..

Find the median of BST in O(N) time and O(1) space.

By Pradipta Choudhury

● Published At Oct 2021

We are given a BST, and we need to find the median of BST in O(N) time complexity and O(1) space.
... Keep reading ..

Kth Largest Element BST

By Harsh Goyal

● Published At Nov 2021

This article will discuss the approach to find out Kth largest element in a Binary Search Tree starting from the brute force approach to the efficient approach.... Keep reading ..

Largest BST subtree in the given Binary Tree

By Nishant Rana

● Published At Oct 2021

This blog will cover the question of finding the Largest BST subtree in the given Binary Tree and optimizing the approach from O(N *N) to O(N).
... Keep reading ..

Count pairs violating BST property

By Urwashi Priya

● Published At Dec 2021

This article will brief you on how to Count pairs violating BST property.
... Keep reading ..

Count BST Nodes that lie in a given Range

By Sneha Mallik

● Published At Oct 2021

This blog covers counting BST nodes that lie in a given range and covers the basic concepts, code and algorithm of binary search trees.
... Keep reading ..

Count of Smaller Numbers After Self

By Soumya Agrawal

● Published At Oct 2021

In this problem, we will aim to find the count of smaller numbers.
... Keep reading ..

Convert a Binary Tree to BST by Left-Shifting digits of Node Values

By Riya

● Published At Feb 2022

This article will discuss the problem “Convert a Binary Tree to BST by Left-Shifting digits of Node Values”, the solution approach to this problem, its C++ implementation, and its time and space complexity.... Keep reading ..

Print nodes of a Binary Search Tree in Top Level Order and Reversed Bottom Level Order alternately

By Gaurish Anand

● Published At Dec 2021

You are given a Binary Search Tree (BST) where you have to print the nodes from the 1st level, then Nth level (in reverse order), 2nd level, (N-1)th level, and so on.... Keep reading ..

Count permutations of the given array that generates the same Binary Search Tree (BST)

By Apoorv

● Published At Feb 2022

This article will discuss the solution to count permutations of the given array that generates the same Binary search tree along with the solution blog will also discuss the time complexity and space complexity for the solution to count permutations... Keep reading ..

Traverse a BST in a min-max manner

By Gaurish Anand

● Published At Dec 2021

You are given a Binary Search Tree (BST). You have to traverse the tree in a min-max manner, i.e., first, travel the minimum of the tree, then maximum and then 2nd minimum, 2nd maximum, and so on.... Keep reading ..

Count the Number of Binary Search Trees present in a Binary Tree

By Ayush Prakash

● Published At Feb 2022

In this blog, we’ll discuss an interesting tree problem: Count the number of Binary search trees in a binary tree. We are also going to discuss the time and space complexities of the approaches covered.
... Keep reading ..

Check if a triplet with given sum exists in BST

By Aditya Narayan Joardar

● Published At Dec 2021

This article discusses how to check if a triplet with a given sum exists in BST or not, using examples and explanations.... Keep reading ..

Maximum height of the binary search tree created from the given array

By Nishant Rana

● Published At Feb 2022

This blog will cover the question to find the maximum height of the Binary Search Tree created from the given array discuss its Time and Space complexity.
... Keep reading ..

Implementing a BST where every node stores the maximum number of nodes in the path till any leaf

By Ayush Prakash

● Published At Feb 2022

In this blog, we will discuss an interesting tree problem: Implementing a binary search tree where every node stores the maximum number of nodes in the path till any leaf. We will also discuss the time and space complexity of the approaches covered.... Keep reading ..

Find the preorder successor of all the nodes in a BST

By Gaurish Anand

● Published At Dec 2021

You are given a Binary Search Tree (BST), and you have to find the pre-order successor of all the nodes.... Keep reading ..

Check If the Two Binary Search Trees are Identical or Not

By Rhythm Jain

● Published At Dec 2021

This article discusses the problem of checking Whether the Two Binary Search Trees are Identical or Not... Keep reading ..

Number of pairs with a given sum in a Binary Search Tree

By Vibhor Bhatnagar

● Published At Dec 2021

This article will discuss the problem to find the number of pairs with a given sum in a Binary Search Tree.... Keep reading ..

Print all pairs from two BSTs whose sum is greater than the given value

By Vibhor Bhatnagar

● Published At Dec 2021

This article will discuss the problem print all pairs from two BSTs whose sum is greater than the given value.... Keep reading ..

Split a BST into two balanced BSTs based on a value V

By Apoorv

● Published At Feb 2022

This article will discuss the solution of the problem statement “Split a BST into two balanced BSTs based on a value V” along with solution this blog will also discuss the time and space complexity for the solution... Keep reading ..

Find the minimum absolute difference in two different BST

By Urwashi Priya

● Published At Dec 2021

This article will brief you on how to Find the minimum absolute difference in two different BST.
... Keep reading ..

Check for Nodes from given two BSTs with a sum equal to X

By Urwashi Priya

● Published At Dec 2021

This article will brief you on how to Check for Nodes from given two BSTs with a sum equal to X
... Keep reading ..

Remove BST nodes having a value in the given range.

By Vaibhav Agarwal

● Published At Dec 2021

In this article, we will discuss the problem to remove BST nodes having a value in the given range. ... Keep reading ..

Find the maximum count of duplicate nodes in a Binary Search Tree

By Vibhor Bhatnagar

● Published At Dec 2021

This article will discuss the problem find the maximum count of duplicate nodes in a binary search tree.... Keep reading ..

Kth Smallest Element in a Perfect Binary Search Tree

By Debarati Ghatak

● Published At Nov 2021

In this blog, we will discuss finding the Kth smallest Element in a Perfect Binary Search Tree. ... Keep reading ..

Convert a Binary Search Tree into a Skewed tree in increasing or decreasing order

By Ayush Prakash

● Published At Feb 2022

This blog will discuss a tree problem: “Convert a Binary Search Tree into a Skewed tree in increasing or decreasing order”. We will also analyse the time and space complexity of all the approaches discussed.
... Keep reading ..

Check if two given key sequences construct the same BSTs

By Apoorv

● Published At Feb 2022

This article will discuss the solution to check if two given key sequences construct the same BSTs or not along with; the solution blog also focuses on time and space complexity for the solution to check whether two given key sequences construct the ... Keep reading ..

Convert a Sorted Linked List to Balanced BST

By Mehak Goel

● Published At Nov 2021

In this blog, we will learn to convert a sorted Linked List to Balanced BST (Binary Search Tree) in the C++ programming language.
... Keep reading ..

Number of BSTs

By Pranav Gautam

● Published At Nov 2021

Learn to find the unique BSTs possible for a given number ‘N’. Learn the application of Catalan numbers.... Keep reading ..

Why Binary Heap is Better than Binary Search Tree (BST) for Priority Queues

By Reet Maggo

● Published At Apr 2022

This article will discuss why Binary Heap is better than Binary Search Tree for Priority Queues by comparing their working.... Keep reading ..

## Top Problems related to Binary Search Tree

Binary Search

Fourth Largest Element in the Array

Search In Rotated Sorted Array

Occurrence of X in a Sorted Array

Remove Duplicates From String

Time To Burn Tree

Next Greater Element

Search In Infinite Sorted 0-1 Array

Position Of First One

Minimum Subarray With Required Sum

Nth Number

Longest Sub-string with at most K Distinct Characters

Longest Substring Without Repeating Characters

Largest Common Ancestor

Partial BST

Convert Bst To The Greater Sum Tree

Kth Largest Element In A Stream

First and Last Position of an element in Sorted Array

Search In A Row Wise And Column Wise Sorted Matrix

Algorithm to find best insert position in sorted array

Climbing the leaderboard