๐ณ Binary Search Tree (BST)
๐น Definition:
A Binary Search Tree is a type of binary tree in which each node has:
-
At most two children: left and right
-
Left child contains nodes less than the parent
-
Right child contains nodes greater than the parent
๐ง Rules of BST:
-
Left subtree has values less than the node
-
Right subtree has values greater than the node
-
No duplicate nodes allowed
๐ง Basic Operations:
| Operation | Purpose |
|---|---|
| Insertion() | Add a new value ๐ Click Here |
| Searching() | Find a value ๐ Click Here |
| Deletion() | Remove a value ๐ Click Here |
| InOrder() | Traverse in sorted order ๐ Click Here |
| PreOrder() | Traverse node → left → right ๐ Click Here |
| PostOrder() | Traverse left → right → node ๐ Click Here |
✅ Advantages:
-
Faster searching than regular binary tree (O(log n) for balanced trees)
-
In-order traversal gives sorted data
❌ Disadvantages:
-
If unbalanced, time complexity can degrade to O(n)
-
Need rebalancing (e.g., using AVL or Red-Black Trees)
๐ Use Cases:
-
Search engines
-
Databases (indexing)
-
File systems
No comments:
Post a Comment