Solution Review: Delete Node

This review provides a detailed analysis of how to delete the x node from a binary search tree.

Solution

For this solution, there can be three cases for the node that needs to be deleted. Let’s call this node x for simplicity. We’ll discuss each case one-by-one.

Case 1: node x has no children

This is a trivial case, in which we just delete the node (by changing the parent node so that it does not point to x). It is done by directly returning null.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.