A binary search tree is a special variant and most commonly used form of binary tree. A binary search tree is made of nodes where each node has at most 2 references, a "left" reference and a "right" reference and a data element. The tree additionally satisfies the binary search tree property, which states that the key in each node must be greater than all keys stored in the left sub-tree, and smaller than all keys in right sub-tree. (The leaves (final nodes) of the tree contain no key and have no structure to distinguish them from one another.
Why to use binary search tree:
Operations on Binary Search Tree
Deleting a node that does not have a leaf root (13) -: Just remove the node.
(8) (8) / \ / \ (2) (21) (2) (21) / \ / ===> / \ (1) (5) (13) (1) (5)
Deleting a node which has a child (21) -: remove the node and move its child up
(8) (8) / \ / \ (2) (21) (2) (13) / \ / ===> / \ (1) (5) (13) (1) (5)
Deleting a node which has two child (2) -: remove the node (2) and swap the node with one of the following:
(8) (8) / \ / \ (2) (21) (2) (13) / \ / ===> / \ (1) (5) (13) (1) (5)
I will be posting the code for operations soon