Binary Search Tree (BST)
Properties of Binary Search Trees #
A Binary Search Tree is a sorted binary tree with the following properties:
- The left subtree of a node contains only nodes with keys less than the node's key.
- The right subtree of a node contains only nodes with keys greater than the node's key.
- Both the left and right subtrees must also be binary search trees.
- Duplicate keys are not allowed.

Due to these characteristics of a Binary Search Tree, efficient searching is possible.
Creation Example #
50, 15, 62, 80, 7, 54, 11
The process of creating a BST using the given elements is as follows:
- Insert 50 into the tree as the root.
- Read the next element. If it is smaller than the root node's element, insert it into the left subtree.
- Otherwise, insert it into the right subtree.

Characteristics of Binary Search Trees #
- By performing an Inorder Traversal of a BST, all keys can be retrieved in sorted order.

The result of an inorder traversal of the above tree is as follows: 8 11 15 50 54 62 80
- The time complexity for searching in a BST is O(logN) if it is balanced, and up to O(N) if it is unbalanced.

Binary Tree Operations #
Search #
Finds the position of a specific element in a Binary Search Tree.
The search process is as follows:
- Start from the root.
- Compare the search value with the root. If it is smaller than the root, recurse on the left; if larger, recurse on the right.
- Repeat the procedure until a matching value is found.
- If the search value is not found, return Null.
Insertion #
Performs the operation of inserting data into a Binary Search Tree. Duplicates are not allowed. New keys are always inserted at leaf nodes.
The insertion process is as follows:
- Start from the root.
- Compare the insertion value with the root. If it is smaller than the root, recurse left; if larger, recurse right.
- After reaching a leaf node, if it is larger than the node, insert it to the right; if smaller, insert it to the left.

Deletion #
Deletes a specific node from a Binary Search Tree. There are three situations for deleting a node in a Binary Search Tree.
- Case 1: The node to be deleted is a leaf node.
Simply delete the node.

- Case 2: The node to be deleted has only one child.
Delete the node and directly connect its child node to the parent of the deleted node.

- Case 3: The node to be deleted has two children.
If there are two children, an additional step of finding the successor node is required.
What is a successor node?
- The minimum value in the right subtree.
- That is, the next node in an inorder traversal.
The deletion process is as follows:
- Find the node to be deleted.
- Find the successor node of the node to be deleted.
- Swap the values of the node to be deleted and its successor node.
- Delete the successor node.
