It is an ordered tree data structure with two leaves per node. The ideal data structure to represent sorted data. In binary search tree, the left child contains nodes with values less than the parent node and where the right child only contains nodes with values greater than the parent node. There must be no duplicate nodes. Searching takes O(log n). In a BST with n nodes, moving from one level to the next requires one comparison, and there are log_2(n) levels, for a total of log_2(n) comparisons.
3 ways to traverse a binary tree. Traversal requires O(n) time, since it must visit every node.
- In Order
- PostOrder
- Pre Order
- Searching
- Building block for most databases
- Many specialized BST's such as RBTree and AVLTree
- Syntax Tree used by compilers