π³ 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