**Prerequisite: Binary Search Tree In JavaScript**

Binary Search Tree Example

Deletion in binary search tree can be tricky, since we’re not working with just leafs but having to restructure all of a node’s children.

Deletion in Binary Search Tree has been divided into 3 cases:

- Node to be deleted is leaf. To delete a leaf node, simply remove it from the tree. Since it was a leaf node we deleted it from the tree without making any other changes.

Remove leaf

- Node to be deleted has only one child. To delete this node, copy the child to the node and delete the child. The node had only one child so we copied its child’s value to it and deleted its child.

Remove node with one child

- Node to be deleted has two children. First, find in-order successor of the node. Now copy contents of the in-order successor to the node and delete the in-order successor. The in-order predecessor can also be used in the same manner.

Remove node with two children

#algorithms #deletion #javascript #data-structures #binary-search-tree #programming

8.05 GEEK