00:00

Binary Tree Vs Binary Search Tree

Last updated:

Every binary search tree is a binary tree, but not every binary tree is a binary search tree. The difference is a single rule about where values may be placed, and that rule changes how fast the tree can be searched. This page defines both and compares them side by side.

What is a Binary Tree?

A binary tree is a tree in which each node has at most two children, called the left child and the right child. The topmost node is the root, and nodes without children are leaves. There is no rule about which values go where.

Binary tree with root 50 in which every node has at most two children

Every node of a binary tree has three parts:

  1. Data
  2. Reference to the left child
  3. Reference to the right child

What is Binary Search Tree?

A binary search tree (BST) is a binary tree with an ordering rule: for every node, all values in its left subtree are smaller and all values in its right subtree are larger. This lets a search discard one subtree at every step.

Binary search tree with root 50: smaller values on the left, larger values on the right

In the tree above, 50 is the root. Its left subtree (rooted at 30) holds only values below 50 and its right subtree (rooted at 70) only values above 50; the same holds at every other node.

Important points of Binary Search Tree (BST)

  • The left subtree of a node contains only keys smaller than the node's key.
  • The right subtree of a node contains only keys larger than the node's key.
  • Both subtrees are themselves binary search trees.
  • Keys are usually unique; duplicates need a fixed rule, such as "equal keys go right" or a count per node.

Difference between Binary Tree and Binary Search Tree

FeatureBinary TreeBinary Search Tree
DefinitionA tree in which every node has at most two children (left and right).A binary tree in which, at every node, all keys in the left subtree are smaller and all keys in the right subtree are larger.
Ordering of valuesNone: any value can be anywhere.Strict: the BST property must hold at every node.
SearchO(n): every node may have to be checked.O(h): one path from the root; O(log n) when balanced, O(n) when degenerate.
InsertionAnywhere you choose (often the first free position in level order).Exactly one correct position, found by comparing from the root.
DeletionAny node can be removed, typically by replacing it with the deepest node.Three cases (leaf, one child, two children) that preserve the ordering.
Inorder traversalValues in no particular order.Values in ascending order.
DuplicatesAllowed anywhere.Usually not allowed, or handled with a fixed rule.
BalancingNot part of the definition.Not guaranteed by a plain BST; AVL and red-black trees add self-balancing.
Typical usesExpression trees, heaps, Huffman trees, hierarchical data.Ordered sets and maps, symbol tables, range queries.

In Summary

Binary tree: a general structure with at most two children per node and no ordering rule; searching it is O(n).

Binary search tree: a binary tree whose values obey the left-smaller, right-larger rule; searching it is O(h), which is O(log n) as long as the tree stays balanced.

Use a plain binary tree when the shape itself carries the meaning (an expression or a heap). Use a binary search tree, ideally a self-balancing one, when you need fast ordered lookups.