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.

Get hands-on with 1400+ tech skills courses.