Data Structures · Binary Search Trees
Need for Binary Search Trees and Search Complexity
Overview
A binary search tree (BST) is a binary tree in which elements are inserted in a proper order so that searching becomes easier. An ordinary binary tree gives no direction for a search and can cost , while a balanced BST reduces search to .
Key concepts
- Binary search tree (BST): a special kind of binary tree in which elements are inserted in a proper order so that searching for an element becomes easier.
The trees that help search for an element are called binary search trees; they have a special property that is very useful while searching. - General binary tree search problem: there is no particular direction to go, so you may end up searching everywhere and might have to go through every node.
- Balanced binary search tree: a BST that has been balanced; it gives good performance, with search time of order .
How it works
- In a normal (general) binary tree, searching for an element may require visiting every node, so the time complexity is of order .
- Visiting every node costs order regardless of traversal: preorder, postorder or inorder all take .
- Insert elements in proper order to get a BST, which makes searching easier.
- Balance the BST to obtain a balanced binary search tree, whose search time is .
Path: ordinary binary tree → search is ; insert elements in proper order to get a BST → search becomes easier; balance the BST → search becomes .

Formulas
- — search in a general binary tree, because in the worst case every node must be visited (preorder, postorder or inorder all take ).
- — search in a balanced binary search tree, achieved by balancing the BST.
- Here = number of nodes in the tree.
Comparison
| Tree type | Search time complexity | Reason |
|---|---|---|
| General binary tree | No direction for search; may have to visit every node (any traversal is ) | |
| Balanced binary search tree | Elements stored in proper order and tree is balanced, so search follows a directed path |
Revision summary
- A BST is a special binary tree where elements are inserted in a proper order to make searching easier.
- A general binary tree gives no particular direction for search, so you may have to search everywhere → .
- Any traversal (preorder, postorder, inorder) of a general binary tree takes because every node is visited.
- Balancing a BST gives search time of order ; such trees are called balanced binary search trees.
- Shortcut: In the GATE exam, small questions are generally asked on this topic — insert these elements into the binary search tree, delete this element, or what is the inorder/preorder of the tree.
Previous-year exam insights
- In a BST, search, insertion and deletion each take time (h = height);
worst case for a skewed tree, for a balanced/AVL tree.
Asked inGATE 2013GATE 2008 - The minimum possible height of a BST on n nodes is ⌊⌋ and the maximum is n−1 (height of a single node = 0).
Asked inGATE 2017 - A BST is uniquely determined by its preorder or postorder sequence together with the BST property (inorder is the sorted order); reconstruction from preorder/postorder takes time.
Asked inGATE 2013GATE 2008 - Inorder traversal of a BST yields the keys in sorted (ascending) order; the minimum key is the leftmost node and the maximum key is the rightmost node.
Asked inGATE 2013GATE 2021 - Reporting all keys in a range [a,b] in a balanced BST costs where k is the number of reported keys ( to locate the range boundaries plus to output).
Asked inGATE 2020GATE 2014 - A max-heap (or min-heap) does not satisfy the BST ordering, so converting a heap to a BST requires sorting, i.e. time, whereas building a heap from a BST takes time.
Asked inGATE 2019