Using C++

Aim : .

To implement the following operations on a Binary Search Tree (BST):

  • Find the Minimum Key
  • Find the Maximum Key
  • Search for a Given Key

Theory

A Binary Search Tree (BST) is a hierarchical data structure that follows these properties:

Algorithm:

1️⃣ Insert a Node into BST

  1. If the tree is empty, create a new node and set it as the root.
  2. Compare the value with the root:
    • If smaller, insert into the left subtree.
    • If larger, insert into the right subtree.

2️⃣ Find the Minimum Key

  1. Start from the root.
  2. Keep moving left until you reach a node with no left child.
  3. That node contains the minimum key.

3️⃣ Find the Maximum Key

  1. Start from the root.
  2. Keep moving right until you reach a node with no right child.
  3. That node contains the maximum key.

4️⃣ Search for a Key in BST

  1. Start at the root.
  2. If the root is NULL, the key does not exist.
  3. If the root's value matches the key, return true.
  4. If the key is smaller, search in the left subtree.
  5. If the key is larger, search in the right subtree.
Program :

Conclusion : Hence we have performed our practical successfully