Binary Search Tree Last Updated : 21 Jun, 2025 Comments Improve Suggest changes Like Article Like Report A Binary Search Tree (BST) is a type of binary tree data structure in which each node contains a unique key and satisfies a specific ordering property:All nodes in the left subtree of a node contain values strictly less than the node’s value. All nodes in the right subtree of a node contain values strictly greater than the node’s value.This structure enables efficient operations for searching, insertion, and deletion of elements, especially when the tree remains balanced. Key Characteristics of a BST:Hierarchical Structure: A BST is composed of nodes, each having up to two children, forming a tree-like hierarchy with a single root node at the top.Ordering Property: For every node in the BST, all values in the left subtree are smaller, and all values in the right subtree are larger than the node’s value. This rule holds recursively for all subtrees.Efficient Operations: In a balanced BST, operations like search, insertion, and deletion can be performed in O(log n) time. In the worst-case (unbalanced), these degrade to O(n). With self-balancing BSTs like AVL and Red Black Trees, we can ensure the worst case as O(Log n).Recursive Nature: Each left or right subtree of a node in a BST is itself a BST, allowing recursive algorithms to naturally process the tree.Practical Applications: BSTs are widely used in database indexing, symbol tables, range queries, and are foundational for advanced structures like AVL trees, Red-Black trees. In problem solving, BSTs are used in problems where we need to maintain sorted stream of data. Introduction to Binary Search:Introduction to BSTApplications of BSTBasic Operations on BST:Insertion in BSTSearching in BSTDeletion in BST Minimum in BSTMaximum in BSTFloor in BSTCeil in BSTInorder Successor in BSTInorder Predecessor in BSTHandling duplicates in BSTEasy Standard Problems on BST:Second largest in BSTSum of k smallest in BSTBST keys in given Range BST to Balanced BSTCheck for BSTBinary Tree to BST Check if array is Inorder of BSTSorted Array to Balanced BSTCheck Same BSTs without constructing BST to Min HeapAdd all greater values in a BSTCheck if two BSTs have same elementsMedium Standard Problems on BST:BST from PreorderSorted Linked List to Balanced BSTTransform a BST to greater sum treeBST to a Tree with sum of all smaller keysConstruct BST from Level Order Check if an array can represent Level Order of BSTMax Sum with No Two Adjacent in BSTLCA in a BSTDistance between two nodes of a BST k-th Smallest in BST Largest BST in a Binary Tree | Set 2Remove all leaves from BST2 sum in BSTMax between two nodes of BSTLargest BST Subtree2 Sum in a Balanced BSTTwo nodes of a BST are swapped, correct itLeaf nodes from Preorder of a BSTHard Standard Problems on BST:Construct all possible BSTs for keys 1 to NIn-place Convert BST into a Min-HeapCheck given array of size n can represent BST of n levels or notMerge two BSTs with limited extra spaceK’th Largest Element in BST when modification to BST is not allowedCheck if given sorted sub-sequence exists in binary search treeMaximum Unique Element in every subarray of size KCount pairs from two BSTs whose sum is equal to a given value xFind if there is a triplet in a Balanced BST that adds to zeroReplace every element with the least greater element on its rightLeaf nodes from Preorder of a Binary Search TreeMinimum Possible value of |ai + aj – k| for given array and k.Special two digit numbers in a Binary Search TreeMerge Two Balanced Binary Search TreesSome Quizzes:‘Quizzes’ on Binary Search Tree‘Quizzes’ on Balanced Binary Search TreesQuick Links :‘Practice Problems’ on Binary Search TreeVideos on Binary Search TreeRecommended:Learn Data Structure and Algorithms | DSA Tutorial Comment More infoAdvertise with us Next Article Introduction to Binary Search Tree H harendrakumar123 Follow Improve Article Tags : Binary Search Tree Data Structures DSA Practice Tags : Binary Search TreeData Structures Similar Reads Binary Search Tree A Binary Search Tree (BST) is a type of binary tree data structure in which each node contains a unique key and satisfies a specific ordering property:All nodes in the left subtree of a node contain values strictly less than the nodeâs value. All nodes in the right subtree of a node contain values s 4 min read Introduction to Binary Search Tree Binary Search Tree is a data structure used in computer science for organizing and storing data in a sorted manner. Binary search tree follows all properties of binary tree and for every nodes, its left subtree contains values less than the node and the right subtree contains values greater than the 3 min read Applications of BST Binary Search Tree (BST) is a data structure that is commonly used to implement efficient searching, insertion, and deletion operations along with maintaining sorted sequence of data. Please remember the following properties of BSTs before moving forward.The left subtree of a node contains only node 3 min read Applications, Advantages and Disadvantages of Binary Search Tree A Binary Search Tree (BST) is a data structure used to storing data in a sorted manner. Each node in a Binary Search Tree has at most two children, a left child and a right child, with the left child containing values less than the parent node and the right child containing values greater than the p 2 min read Insertion in Binary Search Tree (BST) Given a BST, the task is to insert a new node in this BST.Example: How to Insert a value in a Binary Search Tree:A new key is always inserted at the leaf by maintaining the property of the binary search tree. We start searching for a key from the root until we hit a leaf node. Once a leaf node is fo 15 min read Searching in Binary Search Tree (BST) Given a BST, the task is to search a node in this BST. For searching a value in BST, consider it as a sorted array. Now we can easily perform search operation in BST using Binary Search Algorithm. Input: Root of the below BST Output: TrueExplanation: 8 is present in the BST as right child of rootInp 7 min read Deletion in Binary Search Tree (BST) Given a BST, the task is to delete a node in this BST, which can be broken down into 3 scenarios:Case 1. Delete a Leaf Node in BST Case 2. Delete a Node with Single Child in BSTDeleting a single child node is also simple in BST. Copy the child to the node and delete the node. Case 3. Delete a Node w 10 min read Binary Search Tree (BST) Traversals â Inorder, Preorder, Post Order Given a Binary Search Tree, The task is to print the elements in inorder, preorder, and postorder traversal of the Binary Search Tree. Input: A Binary Search TreeOutput: Inorder Traversal: 10 20 30 100 150 200 300Preorder Traversal: 100 20 10 30 200 150 300Postorder Traversal: 10 30 20 150 300 200 1 10 min read Balance a Binary Search Tree Given a BST (Binary Search Tree) that may be unbalanced, the task is to convert it into a balanced BST that has the minimum possible height.Examples: Input: Output: Explanation: The above unbalanced BST is converted to balanced with the minimum possible height.Input: Output: Explanation: The above u 10 min read Self-Balancing Binary Search Trees Self-Balancing Binary Search Trees are height-balanced binary search trees that automatically keep the height as small as possible when insertion and deletion operations are performed on the tree. The height is typically maintained in order of logN so that all operations take O(logN) time on average 4 min read Like