Deletion in Binary Search Tree (Implementation)
Explore how to implement deletion operations in binary search trees using C++. Understand and handle each scenario from deleting empty trees, leaf nodes, nodes with one or two children, and apply these concepts with an efficient code example.
Introduction
Let’s implement the delete function for BSTs. We’ll build upon the code as we cater for each case.
1. Deleting an empty tree
Let’s start with a skeleton function definition and cater for the first case. We return false if the root is NULL.
2. val not found
We search for the tree for the data given, and if it’s not found, i.e., currentNode is NULL, we return false.
3. Deleting a Leaf Node
We first search for the value given to ...