BST_Implementation_Analysis
BST_Implementation_Analysis
Theoretical Part
A Binary Search Tree is a data structure in which each node has at most two children:
1. The left child contains nodes with keys less than the parent node.
2. The right child contains nodes with keys greater than the parent node.
BSTs are widely used due to their ability to perform operations such as insertion, deletion,
1. Insertion
Adds a new key to the BST while maintaining the binary search tree properties. It starts at the root
2. Search
Searches for a specific key by traversing the tree. If the key exists, it returns true; otherwise, false.
3. Deletion
Removes a key from the BST while ensuring the structure of the tree remains valid. There are
three cases:
Balancing a BST ensures that its height is kept as small as possible, leading to efficient operations.
If the tree becomes skewed (e.g., like a linked list), the time complexity of operations degrades to
O(n).
Balanced BSTs, such as AVL or Red-Black Trees, maintain a height close to O(log n), ensuring
optimal
1. Insertion
INSERT(node, key):
if node is NULL:
return CREATE_NEW_NODE(key)
else:
return node
2. Search
SEARCH(node, key):
return node
else:
3. Deletion
DELETE(node, key):
if node is NULL:
return node
else:
if node.left is NULL:
return node.right
return node.left
temp = FIND_MIN(node.right)
node.key = temp.key
return node
FIND_MIN(node):
while node.left is not NULL:
node = node.left
return node
- Insertion:
- Search:
- Deletion:
Maintaining balance ensures all operations remain efficient with O(log n) complexity.