vault backup: 2025-03-16 18:59:42
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# What is a binary search tree, and how does it differ from a regular binary tree?
|
||||
# What is a Binary search Tree, and how Does it Differ from a Regular Binary Tree?
|
||||
|
||||
### **Binary Search Tree (BST):**
|
||||
|
||||
@@ -38,6 +38,7 @@ A **Binary Tree** is a tree data structure where each node has at most two child
|
||||
#### Binary Tree:
|
||||
|
||||
A binary tree with no ordering constraints:
|
||||
|
||||
```
|
||||
10
|
||||
/ \
|
||||
@@ -45,11 +46,13 @@ A binary tree with no ordering constraints:
|
||||
/
|
||||
40
|
||||
```
|
||||
|
||||
- Node values are not in any specific order.
|
||||
|
||||
#### Binary Search Tree:
|
||||
|
||||
A binary search tree:
|
||||
|
||||
```
|
||||
10
|
||||
/ \
|
||||
@@ -64,13 +67,13 @@ A binary search tree:
|
||||
|
||||
---
|
||||
|
||||
### **Advantages of BST Over a General Binary Tree:**
|
||||
### **Advantages Of BST Over a General Binary Tree:**
|
||||
|
||||
1. **Efficient Searching**: Searching in a BST takes $O(h)$, where $h$ is the height of the tree. In a balanced BST, $h=O(logn)$.
|
||||
2. **Ordered Traversal**: In-order traversal of a BST produces the nodes in sorted order.
|
||||
3. **Efficient Range Queries**: BSTs can efficiently find all elements within a specific range.
|
||||
|
||||
### **Disadvantages of BST:**
|
||||
### **Disadvantages Of BST:**
|
||||
|
||||
1. If unbalanced (e.g., when nodes are inserted in sorted order), the BST can degrade to a linked list, resulting in $O(n)$ time for operations.
|
||||
2. Maintaining balance (e.g., in AVL or Red-Black Trees) adds complexity.
|
||||
2. Maintaining balance (e.g., in AVL or Red-Black Trees) adds complexity.
|
||||
|
Reference in New Issue
Block a user