Created
Nov 16, 2025
Last Modified
3 months ago

Binary Search Tree

Binary Search Tree

A Binary Search Tree (BST) is a special type of binary tree.
It can be empty, but if it’s not empty, it follows these rules:

  1. Each node contains a unique key — no duplicates.

  2. Left subtree rule:
    Every key in the left subtree is smaller than the root’s key.

  3. Right subtree rule:
    Every key in the right subtree is greater than the root’s key.

  4. Recursion rule:
    Both left and right subtrees must also be valid BSTs following the same properties.


Number of Comparisons (Sastry & Bhandari)

The number of comparisons required to search for a key in a BST equals the number of nodes visited until the key is found - basically, the depth/level where the key exists.

Total Number of BSTs with N Keys

The total number of distinct BSTs that can be formed using N keys is given by the Nth Catalan Number.


Recurrence Relation

1. Best Case (Perfectly balanced tree)
2. Worst Case (Skewed tree — like a linked list)
3. Average Case