Binary_Search_Tree_Guide
Binary_Search_Tree_Guide
A Binary Search Tree (BST) is a binary tree with the following properties:
- Each node has at most two children, referred to as the left child and the right child.
- For each node, all nodes in its left subtree have values less than the node's value,
and all nodes in its right subtree have values greater than the node's value.
BSTs are used for fast data retrieval, with time complexity O(log n) for balanced trees.
2. BST Operations
BST supports operations like Insertion, Deletion, Searching, and Traversal. Let's cover each:
if (root == NULL) {
return;
Binary Search Tree (BST) Guide
insert(root->left, value);
} else {
insert(root->right, value);
else {
root->data = minValue(root->right);
return root;
// Inorder Traversal
if (root != NULL) {
inorder(root->left);
inorder(root->right);
// Preorder Traversal
if (root != NULL) {
preorder(root->left);
preorder(root->right);
// Postorder Traversal
if (root != NULL) {
postorder(root->left);
postorder(root->right);
- **BST** is a binary tree where the left child is less than the parent node, and the right child is greater.
- **Traversals**: