Explain the difference between Binary Tree and Binary Search Tree (BST).
Updated Apr 28, 2026
Short answer
A Binary Tree is a tree data structure where each node has at most two children, but it does not impose any ordering rule on those children. A Binary Search Tree (BST) is a special type of Binary Tree where every node follows an ordering property: values in the left subtree are smaller than the node's value, and values in the right subtree are larger. This ordering allows BSTs to perform faster searching, insertion, and deletion when they are balanced.
Deep explanation
A Binary Tree is a hierarchical data structure made up of nodes. Each node can have zero, one, or two children, commonly called the left child and right child.
A Binary Tree only defines the structure:
- Each node has at most two children.
- There is a single root node.
- Every child node can itself have its own children.
- There is no requirement about the values stored in the nodes.
Example of a Binary Tree:
10 / \ 5 20 / \ 30 2This is a valid Binary Tree because every node has at most two children. However, it is not a BST because the left child of 5 contains 30, which is greater than 5.
A Binary Search Tree (BST) adds an important rule on top of the Binary Tree structure.
For every node:
- All values in the left subtree are smaller than the node's value.
- All values in the right subtree are larger than the node's value.
- Both left and right subtrees must also follow the same BST rules.
Example of a valid BST:
10 / \ 5 20 / \ / \ 2 7 15 30The BST property makes searching efficient because each comparison eliminates half of the remaining tree in a balanced tree.
For example, searching for 15:
Start at 10:15 > 10, so go right
Move to 20:15 < 20, so go left
Move to 15:Found!Instead of checking every node, the search follows only one path.
Time Complexity Comparison
| Operation | Binary Tree | Balanced BST |
|---|---|---|
| Search | O(n) | O(log n) |
| Insert | O(n) | O(log n) |
| Delete | O(n) | O(log n) |
| Traversal | O(n) | O(n) |
The faster performance of a BST depends on its shape.
A balanced BST:
8 / \ 4 12 / \ / \ 2 6 10 14has a height close to log(n), making operations efficient.
A skewed BST:
1 \ 2 \ 3 \ 4behaves like a linked list. Searching for 4 requires visiting every node, resulting in O(n) time.
Because normal BSTs can become unbalanced, self-balancing BSTs such as AVL trees and Red-Black trees are used when guaranteed performance is needed.
Traversal Difference
Both Binary Trees and BSTs can use the same traversal techniques:
- Preorder: Root → Left → Right
- Inorder: Left → Root → Right
- Postorder: Left → Right → Root
- Level order: Visit nodes level by level
However, inorder traversal has a special property in BSTs:
- In a normal Binary Tree, inorder traversal produces values in no guaranteed order.
- In a BST, inorder traversal always produces values in sorted order.
Example:
BST:
10 / \ 5 20 / \ 2 7Inorder traversal:
2 → 5 → 7 → 10 → 20This sorted output is one of the main advantages of BSTs.
Real-world example
A Binary Search Tree can be used to implement a simple ordered collection of user records.
For example, an application stores users by their unique user IDs. A BST can quickly find a user by comparing the target ID with nodes in the tree.
class Node: def __init__(self, user_id): self.user_id = user_id self.left = None self.right = None
def search(root, target): if root is None or root.user_id == target: return root
if target < root.user_id: return search(root.left, target)
return search(root.right, target)
root = Node(100)root.left = Node(50)root.right = Node(150)
user = search(root, 150)
if user: print("User found")In this example:
- If the target ID is smaller than the current node, the search moves left.
- If the target ID is larger, the search moves right.
- The BST property avoids checking unnecessary nodes.
A normal Binary Tree could store the same user IDs, but it would not know which direction to search, so it may need to visit every node.
Common mistakes
- * Assuming every Binary Tree is a BST
- a BST is only a specialized type of Binary Tree with ordering rules.
- * Thinking that a Binary Tree's left child must always contain a smaller value
- this rule exists only in BSTs.
- * Forgetting that BST performance depends on tree balance
- a skewed BST can degrade to O(n).
- * Confusing tree traversal methods with BST ordering
- traversals apply to both structures, but only inorder traversal of a BST produces sorted values.
- * Allowing duplicate values in a BST without defining a rule
- implementations must decide whether duplicates go left, go right, or are stored separately.
- * Believing that all BST operations are automatically O(log n)
- this is only true for balanced BSTs.
Follow-up questions
- How does insertion work in a Binary Search Tree?
- Why can a Binary Search Tree become inefficient?
- What is the difference between a BST and a Binary Heap?
- Why is inorder traversal special for a BST?
- How do balanced BSTs improve performance?
- Can a Binary Tree be converted into a BST?