Deleting a Node With One Child From a Tree Visually Explained

Trimming the Branches

Exactly what it sounds like. We’ll be deleting a node from a tree that has only one child. Let’s look at our tree and examine which nodes have one child. In our example, only node 33 has one child. All other nodes have two children.

If we removed node 47 from the list, we would have two nodes that have 1 child each; node 40 would have one immediate child and node 33 would have one immediate child. However, let’s keep the example as is. It is important for the reader to have this visual in their head though.

So, how would we delete node 33 from the tree shown above? That’s simple. Node 33’s parent, node 40, would point to node 33’s child after it severs the edge with node 33.

Node 35 would move into the place of node 33. If we examine the binary search tree, we can safely conclude that everything in the left subtree of each parent is less than the parent, and everything in the right subtree of each parent is greater than the parent.

That’s it. Simple.

 

Leave a Reply