Binary search tree

A binary search tree is a special subset of the standard binary tree. The difference lies in the fact that a binary search tree requires that all nodes be sorted into a particular order.

Typically the nodes in a binary search tree are sorted such that for any given sub-tree the left child is smaller than or equal to the root node, and the right child is larger than the root node. Conversely the nodes could be sorted in the exact opposite order (with larger nodes on the left), and equal nodes can be sorted to either side of the parent (though a consistent decision must be made and maintained for the entire tree).

This allows elements in the tree to be searched using a variation of the binary search algorithm, yeilding a result in O(log(n)) time.

A binary search tree (BST) is a binary tree where every node has a value, every node's left subtree contains only values less than or equal to the node's value, and every node's right subtree contains only values that are greater than or equal. The time complexity of searching for a value in a BST is $$O(log(n))$$